From 689fa55d1529ad88449ca464e9107c4dcc54d1cb Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 3 May 2021 11:17:34 +0200 Subject: [PATCH] C++11 tidying. --- src/lib/analyse_subtitles_job.cc | 13 +- src/lib/analyse_subtitles_job.h | 13 +- src/lib/atmos_content.cc | 7 +- src/lib/atmos_content.h | 7 +- src/lib/atmos_decoder.cc | 2 +- src/lib/atmos_decoder.h | 6 +- src/lib/atmos_mxf_content.cc | 27 ++-- src/lib/atmos_mxf_content.h | 12 +- src/lib/atmos_mxf_decoder.cc | 14 ++- src/lib/atmos_mxf_decoder.h | 9 +- src/lib/audio_buffers.cc | 51 ++++++-- src/lib/audio_buffers.h | 4 +- src/lib/butler.cc | 26 +++- src/lib/butler.h | 3 + src/lib/case_insensitive_sorter.cc | 10 +- src/lib/case_insensitive_sorter.h | 4 +- src/lib/content_part.h | 10 +- src/lib/copy_dcp_details_to_film.cc | 2 +- src/lib/copy_dcp_details_to_film.h | 3 +- src/lib/create_cli.cc | 12 +- src/lib/create_cli.h | 5 +- src/lib/cross_osx.cc | 58 ++++++--- src/lib/crypto.cc | 14 ++- src/lib/crypto.h | 6 +- src/lib/curl_uploader.cc | 19 +-- src/lib/curl_uploader.h | 10 +- src/lib/datasat_ap2x.cc | 4 +- src/lib/datasat_ap2x.h | 5 +- src/lib/dcp_content_type.cc | 47 ++++--- src/lib/dcp_content_type.h | 4 +- src/lib/dkdm_recipient.cc | 10 +- src/lib/dkdm_recipient.h | 5 +- src/lib/emailer.cc | 47 ++++--- src/lib/emailer.h | 4 +- src/lib/encode_server_finder.cc | 74 ++++++----- src/lib/encode_server_finder.h | 10 +- src/lib/encoded_log_entry.cc | 6 +- src/lib/encoded_log_entry.h | 4 +- src/lib/event_history.cc | 13 +- src/lib/event_history.h | 6 +- src/lib/exceptions.cc | 36 ++++-- src/lib/exceptions.h | 34 +++++- src/lib/file_log.cc | 16 ++- src/lib/file_log.h | 4 +- src/lib/filter.cc | 20 ++- src/lib/filter.h | 2 +- src/lib/font_data.cc | 2 +- src/lib/font_data.h | 2 +- src/lib/frame_rate_change.cc | 47 +++---- src/lib/frame_rate_change.h | 20 +-- src/lib/log_entry.cc | 10 +- src/lib/log_entry.h | 6 +- src/lib/mid_side_decoder.cc | 36 ++++-- src/lib/mid_side_decoder.h | 4 +- src/lib/overlaps.cc | 7 +- src/lib/overlaps.h | 5 +- src/lib/raw_image_proxy.cc | 32 +++-- src/lib/raw_image_proxy.h | 6 +- src/lib/rng.cc | 2 +- src/lib/rng.h | 2 +- src/lib/scoped_temporary.cc | 13 +- src/lib/scoped_temporary.h | 4 +- src/lib/screen.cc | 20 +-- src/lib/screen.h | 8 +- src/lib/send_notification_email_job.cc | 15 ++- src/lib/send_notification_email_job.h | 10 +- src/lib/send_problem_report_job.cc | 16 ++- src/lib/send_problem_report_job.h | 10 +- src/lib/spl_entry.cc | 20 ++- src/lib/spl_entry.h | 9 +- src/lib/stdout_log.cc | 7 +- src/lib/stdout_log.h | 4 +- src/lib/string_log_entry.cc | 5 +- src/lib/string_log_entry.h | 4 +- src/lib/subtitle_encoder.cc | 34 +++--- src/lib/subtitle_encoder.h | 8 +- src/lib/transcode_job.cc | 41 ++++--- src/lib/transcode_job.h | 16 ++- src/lib/trusted_device.cc | 8 +- src/lib/trusted_device.h | 6 +- src/lib/verify_dcp_job.cc | 10 +- src/lib/verify_dcp_job.h | 11 +- src/lib/video_mxf_content.cc | 28 +++-- src/lib/video_mxf_content.h | 24 ++-- src/lib/video_mxf_decoder.cc | 2 +- src/tools/dcpomatic_batch.cc | 133 ++++++++++---------- src/tools/dcpomatic_combiner.cc | 53 ++++---- src/tools/server_test.cc | 49 ++++---- src/wx/cinema_dialog.cc | 62 +++++----- src/wx/cinema_dialog.h | 6 +- src/wx/dcp_panel.cc | 163 +++++++++++++++---------- src/wx/dcp_panel.h | 9 +- src/wx/file_dialog_wrapper.h | 7 +- src/wx/filter_dialog.cc | 40 +++--- src/wx/filter_dialog.h | 6 +- src/wx/fonts_dialog.cc | 27 ++-- src/wx/fonts_dialog.h | 5 +- src/wx/i18n_hook.cc | 9 +- src/wx/i18n_hook.h | 6 +- src/wx/screen_dialog.cc | 64 +++++----- src/wx/screen_dialog.h | 7 +- src/wx/system_font_dialog.cc | 34 +++--- src/wx/system_font_dialog.h | 6 +- test/audio_mapping_test.cc | 16 ++- test/cinema_sound_processor_test.cc | 8 +- test/colour_conversion_test.cc | 30 +++-- test/dcp_playback_test.cc | 38 +++--- test/file_group_test.cc | 75 ++++++------ test/file_log_test.cc | 10 +- test/image_filename_sorter_test.cc | 49 ++++---- test/image_proxy_test.cc | 19 +-- test/interrupt_encoder_test.cc | 23 ++-- test/kdm_naming_test.cc | 45 ++++--- test/no_use_video_test.cc | 2 +- test/reel_writer_test.cc | 58 ++++----- test/resampler_test.cc | 16 ++- test/socket_test.cc | 13 +- test/subtitle_charset_test.cc | 24 ++-- test/subtitle_language_test.cc | 2 +- test/upmixer_a_test.cc | 31 +++-- 120 files changed, 1464 insertions(+), 893 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 + Copyright (C) 2020-2021 Carl Hetherington 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 #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 film, shared_ptr 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 + Copyright (C) 2020-2021 Carl Hetherington 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 film, std::shared_ptr 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; boost::filesystem::path _path; - boost::optional > _bounding_box; + boost::optional> _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 + Copyright (C) 2020-2021 Carl Hetherington 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::from_xml (Content* parent, cxml::ConstNodePtr node) { if (!node->optional_node_child("AtmosLength")) { - return shared_ptr(); + return {}; } - return shared_ptr (new AtmosContent(parent, node)); + return make_shared(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 + Copyright (C) 2020-2021 Carl Hetherington 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 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 + Copyright (C) 2020-2021 Carl Hetherington 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 + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -30,11 +30,11 @@ class AtmosDecoder : public DecoderPart public: AtmosDecoder (Decoder* parent, std::shared_ptr content); - boost::optional position (std::shared_ptr) const { + boost::optional position (std::shared_ptr) const override { return _position; } - void seek (); + void seek () override; void emit (std::shared_ptr film, std::shared_ptr 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 + Copyright (C) 2016-2021 Carl Hetherington 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 #include #include @@ -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 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 film, shared_ptr job) { job->set_progress_unknown (); Content::examine (film, job); - shared_ptr a (new dcp::AtmosAsset (path(0))); + auto a = make_shared(path(0)); { boost::mutex::scoped_lock lm (_mutex); - atmos.reset (new AtmosContent(this)); + atmos = make_shared(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 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 + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -37,11 +37,11 @@ public: return std::dynamic_pointer_cast (Content::shared_from_this()); } - void examine (std::shared_ptr film, std::shared_ptr job); - std::string summary () const; - void as_xml (xmlpp::Node* node, bool with_path) const; - dcpomatic::DCPTime full_length (std::shared_ptr film) const; - dcpomatic::DCPTime approximate_length () const; + void examine (std::shared_ptr film, std::shared_ptr 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 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 + Copyright (C) 2020-2021 Carl Hetherington 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 #include + +using std::make_shared; using std::shared_ptr; + AtmosMXFDecoder::AtmosMXFDecoder (std::shared_ptr film, std::shared_ptr content) : Decoder (film) , _content (content) { - atmos.reset (new AtmosDecoder(this, content)); + atmos = make_shared(this, content); - shared_ptr asset (new dcp::AtmosAsset(_content->path(0))); + auto asset = make_shared(_content->path(0)); _reader = asset->start_read (); _metadata = AtmosMetadata (asset); } @@ -43,8 +47,8 @@ AtmosMXFDecoder::AtmosMXFDecoder (std::shared_ptr 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 + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,20 +18,23 @@ */ + #include "atmos_metadata.h" #include "dcpomatic_time.h" #include "decoder.h" #include + class AtmosMXFContent; + class AtmosMXFDecoder : public Decoder { public: AtmosMXFDecoder (std::shared_ptr film, std::shared_ptr); - bool pass (); - void seek (dcpomatic::ContentTime t, bool accurate); + bool pass () override; + void seek (dcpomatic::ContentTime t, bool accurate) override; private: std::shared_ptr _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 + Copyright (C) 2012-2021 Carl Hetherington 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 #include + 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 other) { allocate (other->_channels, other->_frames); copy_from (other.get(), other->_frames, 0, 0); } + AudioBuffers::AudioBuffers (std::shared_ptr 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 (malloc (_channels * sizeof (float *))); + _data = static_cast (malloc(_channels * sizeof(float *))); if (!_data) { throw bad_alloc (); } for (int i = 0; i < _channels; ++i) { - _data[i] = static_cast (malloc (frames * sizeof (float))); + _data[i] = static_cast (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 (realloc (_data[i], frames * sizeof (float))); + _data[i] = static_cast (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::channel (int c) const { - shared_ptr o (new AudioBuffers (1, frames ())); + auto o = make_shared(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::clone () const { - shared_ptr b (new AudioBuffers (channels (), frames ())); - b->copy_from (this, frames (), 0, 0); + auto b = make_shared(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 other) @@ -360,6 +386,7 @@ AudioBuffers::append (shared_ptr 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 + Copyright (C) 2012-2021 Carl Hetherington 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 + Copyright (C) 2016-2021 Carl Hetherington 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 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 weak_video) try @@ -331,6 +341,7 @@ catch (...) _died = true; } + void Butler::video (shared_ptr video, DCPTime time) { @@ -341,11 +352,12 @@ Butler::video (shared_ptr video, DCPTime time) return; } - _prepare_service.post (bind (&Butler::prepare, this, weak_ptr(video))); + _prepare_service.post (bind(&Butler::prepare, this, weak_ptr(video))); _video.put (video, time); } + void Butler::audio (shared_ptr audio, DCPTime time, int frame_rate) { @@ -355,9 +367,10 @@ Butler::audio (shared_ptr 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 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 track, DCPTimePeriod period) { @@ -442,6 +459,7 @@ Butler::text (PlayerText pt, TextType type, optional 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 #include + 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 + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,17 +18,19 @@ */ + #include "case_insensitive_sorter.h" #include -#include + 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 + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,8 +18,10 @@ */ + #include + 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 + Copyright (C) 2016-2021 Carl Hetherington 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 + 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 + Copyright (C) 2020-2021 Carl Hetherington 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 + Copyright (C) 2020-2021 Carl Hetherington 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 dcp, std::shared_ptr 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 + Copyright (C) 2019-2021 Carl Hetherington 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 +#include #include -#include using std::string; using std::cout; using boost::optional; + string CreateCLI::_help = "\nSyntax: %1 [OPTION] [OPTION] [ ...]\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 void argument_option (int& n, int argc, char* argv[], string short_name, string long_name, bool* claimed, optional* 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 + Copyright (C) 2019-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,15 +18,18 @@ */ + #include "types.h" #include #include #include #include + 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 + Copyright (C) 2012-2021 Carl Hetherington 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 > + +list> mount_info () { - list > 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 get_vendor (CFDictionaryRef& description) { @@ -273,6 +289,7 @@ get_vendor (CFDictionaryRef& description) return s; } + static optional 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 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 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*>(context)->push_back(this_disk); } + vector Drive::get () { using namespace boost::algorithm; vector 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 > mounted_synths; + map> 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 + Copyright (C) 2018-2021 Carl Hetherington 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 @@ -28,12 +30,15 @@ #include #include + 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 + Copyright (C) 2018-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,14 +18,18 @@ */ + #include + 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 + Copyright (C) 2015-2021 Carl Hetherington 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 set_status, function 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 set_status, functiontms_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 + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,9 +18,11 @@ */ + #include "uploader.h" #include + 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 + Copyright (C) 2019-2021 Carl Hetherington 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 + Copyright (C) 2019-2021 Carl Hetherington 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 + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -27,10 +27,14 @@ #include "i18n.h" + +using boost::optional; using namespace std; + vector 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 DCPContentType::as_index (DCPContentType const * c) { vector::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::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 + Copyright (C) 2012-2021 Carl Hetherington 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 as_index (DCPContentType const *); static std::vector 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 + Copyright (C) 2020-2021 Carl Hetherington 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 +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(), 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(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 + Copyright (C) 2020-2021 Carl Hetherington 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 + Copyright (C) 2015-2021 Carl Hetherington 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 to, string subject, string body) : _from (from) , _to (to) @@ -46,6 +49,7 @@ Emailer::Emailer (string from, list 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(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(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::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::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 addresses) { @@ -239,6 +251,7 @@ Emailer::address_list (list 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 + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,9 +18,11 @@ */ + #include #include + 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 + Copyright (C) 2013-2021 Carl Hetherington 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 (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(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::iterator i = _servers.begin(); + auto i = _servers.begin(); while (i != _servers.end()) { if (i->last_seen_seconds() > 2 * interval) { - list::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 (new Socket ()); + auto socket = make_shared(); _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) { @@ -209,18 +220,18 @@ EncodeServerFinder::handle_accept (boost::system::error_code ec, shared_ptrread (reinterpret_cast (&length), sizeof (uint32_t)); + socket->read (reinterpret_cast(&length), sizeof(uint32_t)); length = ntohl (length); - scoped_array buffer (new char[length]); - socket->read (reinterpret_cast (buffer.get()), length); + scoped_array buffer(new char[length]); + socket->read (reinterpret_cast(buffer.get()), length); string s (buffer.get()); - shared_ptr xml (new cxml::Document ("ServerAvailable")); + auto xml = make_shared("ServerAvailable"); xml->read_string (s); - string const ip = socket->socket().remote_endpoint().address().to_string (); - optional::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::iterator> EncodeServerFinder::server_found (string ip) { boost::mutex::scoped_lock lm (_servers_mutex); - list::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::iterator>(); + return {}; } + EncodeServerFinder* EncodeServerFinder::instance () { @@ -262,13 +275,15 @@ EncodeServerFinder::instance () return _instance; } + void EncodeServerFinder::drop () { delete _instance; - _instance = 0; + _instance = nullptr; } + list 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 + Copyright (C) 2013-2021 Carl Hetherington 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 #include + 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 + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,11 +18,14 @@ */ + #include "encoded_log_entry.h" #include + 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 + Copyright (C) 2015-2021 Carl Hetherington 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 + Copyright (C) 2017-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,24 +18,28 @@ */ + #include "event_history.h" #include "util.h" #include + using boost::optional; + EventHistory::EventHistory (int size) : _size (size) { } + optional EventHistory::rate () const { boost::mutex::scoped_lock lock (_mutex); - if (int (_history.size()) < _size) { - return optional(); + 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 + Copyright (C) 2017-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,13 +18,16 @@ */ + #ifndef DCPOMATIC_EVENT_HISTORY_H #define DCPOMATIC_EVENT_HISTORY_H + #include #include #include + 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 + Copyright (C) 2012-2021 Carl Hetherington 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 n) : runtime_error (String::compose("%1%2", m, n ? String::compose(" (%1)", *n) : "")) , _message (m) @@ -124,12 +140,14 @@ CopyError::CopyError (string m, optional 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 + Copyright (C) 2012-2021 Carl Hetherington 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 } #include #include -#include #include +#include + /** @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 + Copyright (C) 2012-2021 Carl Hetherington 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 #include + 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 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 + Copyright (C) 2012-2021 Carl Hetherington 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 + Copyright (C) 2012-2021 Carl Hetherington 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 @@ -30,10 +32,13 @@ extern "C" { #include "i18n.h" + using namespace std; + vector 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::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 const & filters) return ff; } + /** @param d Our id. * @return Corresponding Filter, or 0. */ Filter const * Filter::from_id (string d) { - vector::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 + Copyright (C) 2012-2021 Carl Hetherington 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 + Copyright (C) 2020-2021 Carl Hetherington 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 + Copyright (C) 2020-2021 Carl Hetherington 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 + Copyright (C) 2012-2021 Carl Hetherington 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 film, shared_ptr 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 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 + Copyright (C) 2012-2021 Carl Hetherington 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 + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,12 +18,14 @@ */ + #include "log_entry.h" #include #include #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 (_time.tv_sec), static_cast (_time.tv_usec)); + snprintf (buffer, sizeof(buffer), "%" PRId64 ":%" PRId64 " ", static_cast(_time.tv_sec), static_cast(_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 + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,12 +18,15 @@ */ + #ifndef DCPOMATIC_LOG_ENTRY_H #define DCPOMATIC_LOG_ENTRY_H + #include #include + 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 + Copyright (C) 2014-2021 Carl Hetherington 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 MidSideDecoder::clone (int) const { - return shared_ptr (new MidSideDecoder ()); + return make_shared(); } + shared_ptr MidSideDecoder::run (shared_ptr in, int channels) { int const N = min (channels, 3); - shared_ptr out (new AudioBuffers (channels, in->frames ())); + auto out = make_shared(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 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 MidSideDecoder::input_names () const { - vector 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 + Copyright (C) 2014-2021 Carl Hetherington 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 + Copyright (C) 2013-2021 Carl Hetherington 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 film, ContentList cl, function)> 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 + Copyright (C) 2013-2021 Carl Hetherington 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 + Copyright (C) 2014-2021 Carl Hetherington 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) { } + RawImageProxy::RawImageProxy (shared_ptr xml, shared_ptr socket) { dcp::Size size ( - xml->number_child ("Width"), xml->number_child ("Height") + xml->number_child("Width"), xml->number_child("Height") ); - _image.reset (new Image (static_cast (xml->number_child ("PixelFormat")), size, true)); + _image = make_shared(static_cast(xml->number_child("PixelFormat")), size, true); _image->read_from_socket (socket); } + ImageProxy::Result RawImageProxy::image (optional) 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 (_image->size().width)); - node->add_child("Height")->add_child_text (raw_convert (_image->size().height)); - node->add_child("PixelFormat")->add_child_text (raw_convert (static_cast (_image->pixel_format ()))); + node->add_child("Type")->add_child_text(N_("Raw")); + node->add_child("Width")->add_child_text(raw_convert(_image->size().width)); + node->add_child("Height")->add_child_text(raw_convert(_image->size().height)); + node->add_child("PixelFormat")->add_child_text(raw_convert(static_cast(_image->pixel_format()))); } + void RawImageProxy::write_to_socket (shared_ptr socket) const { _image->write_to_socket (socket); } + bool RawImageProxy::same (shared_ptr other) const { - shared_ptr rp = dynamic_pointer_cast (other); + auto rp = dynamic_pointer_cast (other); if (!rp) { return false; } @@ -89,6 +98,7 @@ RawImageProxy::same (shared_ptr 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 + Copyright (C) 2014-2021 Carl Hetherington 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; }; + #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 + Copyright (C) 2020-2021 Carl Hetherington 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 + Copyright (C) 2020-2021 Carl Hetherington 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 + Copyright (C) 2012-2021 Carl Hetherington 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 + Copyright (C) 2012-2021 Carl Hetherington 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 + Copyright (C) 2013-2021 Carl Hetherington 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 #include -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 Screen::trusted_device_thumbprints () const { @@ -78,14 +84,14 @@ kdm_for_screen ( ) { if (!screen->recipient) { - return KDMWithMetadataPtr(); + return {}; } - shared_ptr 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(), kdm)); + return make_shared(name_values, cinema.get(), cinema ? cinema->emails : list(), 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 + Copyright (C) 2013-2021 Carl Hetherington 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 #include + 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 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 + Copyright (C) 2018-2021 Carl Hetherington 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()) @@ -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 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 + Copyright (C) 2018-2021 Carl Hetherington 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 + Copyright (C) 2014-2021 Carl Hetherington 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 + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,10 +18,12 @@ */ + #include "job.h" #include #include + 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 + Copyright (C) 2018-2021 Carl Hetherington 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 DCPOMATIC_ENABLE_WARNINGS + using std::shared_ptr; using std::dynamic_pointer_cast; -SPLEntry::SPLEntry (shared_ptr content) -{ - construct (content); -} -void -SPLEntry::construct (shared_ptr c) +SPLEntry::SPLEntry (shared_ptr c) + : content (c) + , digest (content->digest()) { - content = c; - shared_ptr dcp = dynamic_pointer_cast (content); - digest = content->digest (); + auto dcp = dynamic_pointer_cast (content); if (dcp) { name = dcp->name (); DCPOMATIC_ASSERT (dcp->cpl()); @@ -52,6 +49,7 @@ SPLEntry::construct (shared_ptr 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 + Copyright (C) 2018-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,22 +18,26 @@ */ + #ifndef DCPOMATIC_SPL_ENTRY_H #define DCPOMATIC_SPL_ENTRY_H + #include #include + namespace xmlpp { class Element; } class Content; + class SPLEntry { public: - SPLEntry (std::shared_ptr content); + SPLEntry (std::shared_ptr c); void as_xml (xmlpp::Element* e); @@ -50,4 +54,5 @@ private: void construct (std::shared_ptr 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 + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,24 +18,29 @@ */ + #include "stdout_log.h" #include "config.h" #include + 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 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 + Copyright (C) 2012-2021 Carl Hetherington 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 + Copyright (C) 2015-2021 Carl Hetherington 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 + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,9 +18,11 @@ */ + #include "log_entry.h" #include + 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 + Copyright (C) 2019-2021 Carl Hetherington 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 #include #include @@ -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 film, shared_ptr 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, 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 s (new dcp::InteropSubtitleAsset()); + auto s = make_shared(); s->set_movie_title (_film->name()); s->set_reel_number (raw_convert(reel + 1)); - i->first = s; + i.first = s; } else { - shared_ptr s (new dcp::SMPTESubtitleAsset()); + auto s = make_shared(); 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 track, dcpomatic::DCPTimePeriod period) { @@ -170,7 +175,7 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional tr if (_film->interop() && !_include_font) { i.unset_font (); } - _assets[_reel_index].first->add (shared_ptr(new dcp::SubtitleString(i))); + _assets[_reel_index].first->add (make_shared(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 tr _last = period.from; - shared_ptr 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 + Copyright (C) 2019-2021 Carl Hetherington 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 film, std::shared_ptr 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 + Copyright (C) 2012-2021 Carl Hetherington 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 +#include "transcode_job.h" +#include "upload_job.h" #include +#include #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 film) : Job (film) @@ -53,29 +58,34 @@ TranscodeJob::TranscodeJob (shared_ptr 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 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(_encoder)) { - shared_ptr job (new UploadJob (_film)); - JobManager::instance()->add (job); + JobManager::instance()->add(make_shared(_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 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 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 + Copyright (C) 2012-2021 Carl Hetherington 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 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 t); private: - int remaining_time () const; + int remaining_time () const override; std::shared_ptr _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 + Copyright (C) 2013-2021 Carl Hetherington 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 + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,13 +18,16 @@ */ + #ifndef DCPOMATIC_TRUSTED_DEVICE_H #define DCPOMATIC_TRUSTED_DEVICE_H + #include #include #include + class TrustedDevice { public: @@ -43,4 +46,5 @@ private: boost::optional _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 + Copyright (C) 2018-2021 Carl Hetherington 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 directories) : Job (shared_ptr()) , _directories (directories) @@ -39,23 +42,27 @@ VerifyDCPJob::VerifyDCPJob (vector 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 path) { @@ -65,6 +72,7 @@ VerifyDCPJob::update_stage (string s, optional 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 + Copyright (C) 2018-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,20 +18,23 @@ */ + #include "job.h" #include + class Content; + class VerifyDCPJob : public Job { public: explicit VerifyDCPJob (std::vector 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 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 + Copyright (C) 2016-2021 Carl Hetherington 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 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 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 film, shared_ptr job) { @@ -86,50 +93,57 @@ VideoMXFContent::examine (shared_ptr film, shared_ptr job) Content::examine (film, job); video.reset (new VideoContent (this)); - shared_ptr examiner (new VideoMXFExaminer (shared_from_this ())); + auto examiner = make_shared(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 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 film, list& 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 + Copyright (C) 2016-2021 Carl Hetherington 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 shared_from_this () { - return std::dynamic_pointer_cast (Content::shared_from_this ()); + return std::dynamic_pointer_cast(Content::shared_from_this()); } std::shared_ptr shared_from_this () const { - return std::dynamic_pointer_cast (Content::shared_from_this ()); + return std::dynamic_pointer_cast(Content::shared_from_this()); } - void examine (std::shared_ptr film, std::shared_ptr 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 film) const; - dcpomatic::DCPTime approximate_length () const; - void add_properties (std::shared_ptr film, std::list& p) const; + void examine (std::shared_ptr film, std::shared_ptr 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 film) const override; + dcpomatic::DCPTime approximate_length () const override; + void add_properties (std::shared_ptr film, std::list& 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 + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. diff --git a/src/tools/dcpomatic_batch.cc b/src/tools/dcpomatic_batch.cc index 9cb6ddc55..061470602 100644 --- a/src/tools/dcpomatic_batch.cc +++ b/src/tools/dcpomatic_batch.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2019 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,56 +18,62 @@ */ -#include "wx/wx_util.h" + #include "wx/about_dialog.h" -#include "wx/wx_signal_manager.h" -#include "wx/job_manager_view.h" +#include "wx/dcpomatic_button.h" #include "wx/full_config_dialog.h" +#include "wx/job_manager_view.h" #include "wx/servers_list_dialog.h" -#include "wx/dcpomatic_button.h" -#include "lib/version.h" +#include "wx/wx_signal_manager.h" +#include "wx/wx_util.h" #include "lib/compose.hpp" #include "lib/config.h" -#include "lib/util.h" +#include "lib/dcpomatic_socket.h" #include "lib/film.h" -#include "lib/job_manager.h" #include "lib/job.h" -#include "lib/dcpomatic_socket.h" +#include "lib/job_manager.h" #include "lib/transcode_job.h" +#include "lib/util.h" +#include "lib/version.h" #include -#include #include -#include #include +#include +#include #include #include #include -using std::exception; -using std::string; + using std::cout; +using std::dynamic_pointer_cast; +using std::exception; using std::list; +using std::make_shared; using std::set; using std::shared_ptr; -using boost::thread; +using std::string; using boost::scoped_array; -using std::dynamic_pointer_cast; +using boost::thread; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif + static list films_to_load; + enum { ID_file_add_film = 1, ID_tools_encoding_servers, ID_help_about }; + void setup_menu (wxMenuBar* m) { - wxMenu* file = new wxMenu; + auto file = new wxMenu; file->Append (ID_file_add_film, _("&Add Film...\tCtrl-A")); #ifdef DCPOMATIC_OSX file->Append (wxID_EXIT, _("&Exit")); @@ -78,14 +84,14 @@ setup_menu (wxMenuBar* m) #ifdef DCPOMATIC_OSX file->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P")); #else - wxMenu* edit = new wxMenu; + auto edit = new wxMenu; edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P")); #endif - wxMenu* tools = new wxMenu; + auto tools = new wxMenu; tools->Append (ID_tools_encoding_servers, _("Encoding servers...")); - wxMenu* help = new wxMenu; + auto help = new wxMenu; help->Append (ID_help_about, _("About")); m->Append (file, _("&File")); @@ -96,16 +102,15 @@ setup_menu (wxMenuBar* m) m->Append (help, _("&Help")); } + class DOMFrame : public wxFrame { public: explicit DOMFrame (wxString const & title) - : wxFrame (NULL, -1, title) - , _sizer (new wxBoxSizer (wxVERTICAL)) - , _config_dialog (0) - , _servers_list_dialog (0) + : wxFrame (nullptr, -1, title) + , _sizer (new wxBoxSizer(wxVERTICAL)) { - wxMenuBar* bar = new wxMenuBar; + auto bar = new wxMenuBar; setup_menu (bar); SetMenuBar (bar); @@ -117,17 +122,17 @@ public: Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_encoding_servers, this), ID_tools_encoding_servers); Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), ID_help_about); - wxPanel* panel = new wxPanel (this); - wxSizer* s = new wxBoxSizer (wxHORIZONTAL); + auto panel = new wxPanel (this); + auto s = new wxBoxSizer (wxHORIZONTAL); s->Add (panel, 1, wxEXPAND); SetSizer (s); - JobManagerView* job_manager_view = new JobManagerView (panel, true); + auto job_manager_view = new JobManagerView (panel, true); _sizer->Add (job_manager_view, 1, wxALL | wxEXPAND, 6); - wxSizer* buttons = new wxBoxSizer (wxHORIZONTAL); - wxButton* add = new Button (panel, _("Add Film...")); - add->Bind (wxEVT_BUTTON, boost::bind (&DOMFrame::add_film, this)); + auto buttons = new wxBoxSizer (wxHORIZONTAL); + auto add = new Button (panel, _("Add Film...")); + add->Bind (wxEVT_BUTTON, boost::bind(&DOMFrame::add_film, this)); buttons->Add (add, 1, wxALL, 6); _pause = new Button (panel, _("Pause")); _pause->Bind (wxEVT_BUTTON, boost::bind(&DOMFrame::pause, this)); @@ -142,8 +147,8 @@ public: panel->SetSizer (_sizer); - Bind (wxEVT_CLOSE_WINDOW, boost::bind (&DOMFrame::close, this, _1)); - Bind (wxEVT_SIZE, boost::bind (&DOMFrame::sized, this, _1)); + Bind (wxEVT_CLOSE_WINDOW, boost::bind(&DOMFrame::close, this, _1)); + Bind (wxEVT_SIZE, boost::bind(&DOMFrame::sized, this, _1)); } void setup_sensitivity () @@ -154,20 +159,20 @@ public: void pause () { - JobManager::instance()->pause (); + JobManager::instance()->pause(); setup_sensitivity (); } void resume () { - JobManager::instance()->resume (); + JobManager::instance()->resume(); setup_sensitivity (); } void start_job (boost::filesystem::path path) { try { - shared_ptr film (new Film (path)); + auto film = make_shared(path); film->read_metadata (); double total_required; @@ -176,7 +181,7 @@ public: film->should_be_enough_disk_space (total_required, available, can_hard_link); - set > films; + set> films; for (auto i: JobManager::instance()->get()) { films.insert (i->film()); @@ -208,9 +213,9 @@ public: film->make_dcp (); } catch (std::exception& e) { - wxString p = std_to_wx (path.string ()); - wxCharBuffer b = p.ToUTF8 (); - error_dialog (this, wxString::Format (_("Could not open film at %s"), p.data()), std_to_wx(e.what())); + auto p = std_to_wx (path.string ()); + auto b = p.ToUTF8 (); + error_dialog (this, wxString::Format(_("Could not open film at %s"), p.data()), std_to_wx(e.what())); } } @@ -223,11 +228,11 @@ private: bool should_close () { - if (!JobManager::instance()->work_to_do ()) { + if (!JobManager::instance()->work_to_do()) { return true; } - wxMessageDialog* d = new wxMessageDialog ( + auto d = new wxMessageDialog ( 0, _("There are unfinished jobs; are you sure you want to quit?"), _("Unfinished jobs"), @@ -241,7 +246,7 @@ private: void close (wxCloseEvent& ev) { - if (!should_close ()) { + if (!should_close()) { ev.Veto (); return; } @@ -256,7 +261,7 @@ private: void file_quit () { - if (should_close ()) { + if (should_close()) { Close (true); } } @@ -280,16 +285,16 @@ private: void help_about () { - AboutDialog* d = new AboutDialog (this); + auto d = new AboutDialog (this); d->ShowModal (); d->Destroy (); } void add_film () { - wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST); + auto c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST); if (_last_parent) { - c->SetPath (std_to_wx (_last_parent.get().string ())); + c->SetPath (std_to_wx(_last_parent.get().string())); } int r; @@ -320,7 +325,7 @@ private: } catch (exception& e) { error_dialog ( this, - wxString::Format ( + wxString::Format( _("Could not write to cinemas file at %s. Your changes have not been saved."), std_to_wx (Config::instance()->cinemas_file().string()).data() ) @@ -332,7 +337,7 @@ private: } catch (exception& e) { error_dialog ( this, - wxString::Format ( + wxString::Format( _("Could not write to config file at %s. Your changes have not been saved."), std_to_wx (Config::instance()->cinemas_file().string()).data() ) @@ -343,17 +348,19 @@ private: boost::optional _last_parent; wxSizer* _sizer; - wxPreferencesEditor* _config_dialog; - ServersListDialog* _servers_list_dialog; + wxPreferencesEditor* _config_dialog = nullptr; + ServersListDialog* _servers_list_dialog = nullptr; wxButton* _pause; wxButton* _resume; }; + static const wxCmdLineEntryDesc command_line_description[] = { { wxCMD_LINE_PARAM, 0, 0, "film to load", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 } }; + class JobServer : public Server { public: @@ -366,11 +373,11 @@ public: { try { int const length = socket->read_uint32 (); - scoped_array buffer (new char[length]); - socket->read (reinterpret_cast (buffer.get()), length); + scoped_array buffer(new char[length]); + socket->read (reinterpret_cast(buffer.get()), length); string s (buffer.get()); _frame->start_job (s); - socket->write (reinterpret_cast ("OK"), 3); + socket->write (reinterpret_cast("OK"), 3); } catch (...) { } @@ -380,6 +387,7 @@ private: DOMFrame* _frame; }; + class App : public wxApp { bool OnInit () @@ -389,10 +397,10 @@ class App : public wxApp SetAppName (_("DCP-o-matic Batch Converter")); is_batch_converter = true; - Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this)); - Config::Warning.connect (boost::bind (&App::config_warning, this, _1)); + Config::FailedToLoad.connect (boost::bind(&App::config_failed_to_load, this)); + Config::Warning.connect (boost::bind(&App::config_warning, this, _1)); - wxSplashScreen* splash = maybe_show_splash (); + auto splash = maybe_show_splash (); if (!wxApp::OnInit()) { return false; @@ -430,7 +438,7 @@ class App : public wxApp } _frame->Show (); - JobServer* server = new JobServer (_frame); + auto server = new JobServer (_frame); new thread (boost::bind (&JobServer::run, server)); signal_manager = new wxSignalManager (this); @@ -438,15 +446,15 @@ class App : public wxApp shared_ptr film; for (auto i: films_to_load) { - if (boost::filesystem::is_directory (i)) { + if (boost::filesystem::is_directory(i)) { try { - film.reset (new Film (i)); + film = make_shared(i); film->read_metadata (); film->make_dcp (); } catch (exception& e) { error_dialog ( 0, - std_to_wx (String::compose (wx_to_std (_("Could not load film %1")), i.string())), + std_to_wx(String::compose(wx_to_std(_("Could not load film %1")), i.string())), std_to_wx(e.what()) ); } @@ -470,7 +478,7 @@ class App : public wxApp bool OnCmdLineParsed (wxCmdLineParser& parser) { for (size_t i = 0; i < parser.GetParamCount(); ++i) { - films_to_load.push_back (wx_to_std (parser.GetParam(i))); + films_to_load.push_back (wx_to_std(parser.GetParam(i))); } return true; @@ -483,10 +491,11 @@ class App : public wxApp void config_warning (string m) { - message_dialog (_frame, std_to_wx (m)); + message_dialog (_frame, std_to_wx(m)); } DOMFrame* _frame; }; + IMPLEMENT_APP (App) diff --git a/src/tools/dcpomatic_combiner.cc b/src/tools/dcpomatic_combiner.cc index 886c1c613..566ec82f1 100644 --- a/src/tools/dcpomatic_combiner.cc +++ b/src/tools/dcpomatic_combiner.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -37,12 +37,13 @@ DCPOMATIC_ENABLE_WARNINGS #include +using std::dynamic_pointer_cast; using std::exception; +using std::make_shared; +using std::shared_ptr; using std::string; using std::vector; -using std::dynamic_pointer_cast; using boost::optional; -using std::shared_ptr; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif @@ -80,13 +81,13 @@ class DOMFrame : public wxFrame { public: explicit DOMFrame (wxString const & title) - : wxFrame (0, -1, title) + : wxFrame (nullptr, -1, title) { /* Use a panel as the only child of the Frame so that we avoid the dark-grey background on Windows. */ - wxPanel* overall_panel = new wxPanel (this); - wxSizer* s = new wxBoxSizer (wxHORIZONTAL); + auto overall_panel = new wxPanel (this); + auto s = new wxBoxSizer (wxHORIZONTAL); s->Add (overall_panel, 1, wxEXPAND); SetSizer (s); @@ -103,14 +104,14 @@ public: true ); - wxBoxSizer* output = new wxBoxSizer (wxHORIZONTAL); + auto output = new wxBoxSizer (wxHORIZONTAL); add_label_to_sizer (output, overall_panel, _("Output DCP folder"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); _output = new DirPickerCtrl (overall_panel); output->Add (_output, 1, wxEXPAND); _combine = new Button (overall_panel, _("Combine")); - wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL); + auto sizer = new wxBoxSizer (wxVERTICAL); sizer->Add (_input, 1, wxALL | wxEXPAND, DCPOMATIC_DIALOG_BORDER); sizer->Add (output, 0, wxALL | wxEXPAND, DCPOMATIC_DIALOG_BORDER); sizer->Add (_combine, 0, wxALL | wxALIGN_RIGHT, DCPOMATIC_DIALOG_BORDER); @@ -137,9 +138,11 @@ private: void combine () { - boost::filesystem::path const output = wx_to_std(_output->GetPath()); + using namespace boost::filesystem; + + path const output = wx_to_std(_output->GetPath()); - if (boost::filesystem::is_directory(output) && !boost::filesystem::is_empty(output)) { + if (is_directory(output) && !is_empty(output)) { if (!confirm_dialog ( this, std_to_wx ( @@ -150,7 +153,7 @@ private: )) { return; } - } else if (boost::filesystem::is_regular_file(output)) { + } else if (is_regular_file(output)) { error_dialog ( this, String::compose (wx_to_std(_("%1 already exists as a file, so you cannot use it for a DCP.")), output.string()) @@ -158,21 +161,21 @@ private: return; } - JobManager* jm = JobManager::instance (); - jm->add (shared_ptr(new CombineDCPJob(_inputs, output))); + auto jm = JobManager::instance (); + jm->add (make_shared(_inputs, output)); bool const ok = display_progress (_("DCP-o-matic Combine"), _("Combining DCPs")); if (!ok) { return; } DCPOMATIC_ASSERT (!jm->get().empty()); - shared_ptr last = dynamic_pointer_cast (jm->get().back()); + auto last = dynamic_pointer_cast (jm->get().back()); DCPOMATIC_ASSERT (last); if (last->finished_ok()) { message_dialog (this, _("DCPs combined successfully.")); } else { - wxString m = std_to_wx(last->error_summary()); + auto m = std_to_wx(last->error_summary()); if (!last->error_details().empty()) { m += wxString::Format(" (%s)", std_to_wx(last->error_details())); } @@ -195,11 +198,9 @@ private: class App : public wxApp { public: - App () - : _frame (0) - {} + App () {} - bool OnInit () + bool OnInit () override { try { Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this)); @@ -249,7 +250,7 @@ public: } catch (exception& e) { - error_dialog (0, wxString::Format ("DCP-o-matic DCP Combiner could not start."), std_to_wx(e.what())); + error_dialog (nullptr, wxString::Format ("DCP-o-matic DCP Combiner could not start."), std_to_wx(e.what())); return false; } @@ -279,7 +280,7 @@ public: } catch (FileError& e) { error_dialog ( 0, - wxString::Format ( + wxString::Format( _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM, std_to_wx (e.what()), std_to_wx (e.file().string().c_str ()) @@ -288,29 +289,29 @@ public: } catch (exception& e) { error_dialog ( 0, - wxString::Format ( + wxString::Format( _("An exception occurred: %s.\n\n") + REPORT_PROBLEM, std_to_wx (e.what ()) ) ); } catch (...) { - error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM); + error_dialog (nullptr, _("An unknown exception occurred.") + " " + REPORT_PROBLEM); } } - bool OnExceptionInMainLoop () + bool OnExceptionInMainLoop () override { report_exception (); /* This will terminate the program */ return false; } - void OnUnhandledException () + void OnUnhandledException () override { report_exception (); } - DOMFrame* _frame; + DOMFrame* _frame = nullptr; }; IMPLEMENT_APP (App) diff --git a/src/tools/server_test.cc b/src/tools/server_test.cc index 8e4496799..6c7371253 100644 --- a/src/tools/server_test.cc +++ b/src/tools/server_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,29 +18,32 @@ */ -#include "lib/ratio.h" -#include "lib/film.h" -#include "lib/filter.h" -#include "lib/util.h" -#include "lib/encode_server.h" + #include "lib/dcp_video.h" #include "lib/decoder.h" +#include "lib/encode_server.h" +#include "lib/encode_server_description.h" #include "lib/exceptions.h" #include "lib/file_log.h" -#include "lib/video_decoder.h" +#include "lib/film.h" +#include "lib/filter.h" #include "lib/player.h" #include "lib/player_video.h" -#include "lib/encode_server_description.h" +#include "lib/ratio.h" +#include "lib/util.h" +#include "lib/video_decoder.h" #include -#include -#include #include +#include +#include + -using std::cout; using std::cerr; -using std::string; +using std::cout; +using std::make_shared; using std::pair; using std::shared_ptr; +using std::string; using boost::optional; using boost::bind; #if BOOST_VERSION >= 106100 @@ -48,22 +51,24 @@ using namespace boost::placeholders; #endif using dcp::ArrayData; + static shared_ptr film; static EncodeServerDescription* server; static int frame_count = 0; + void process_video (shared_ptr pvf) { - shared_ptr local (new DCPVideo (pvf, frame_count, film->video_frame_rate(), 250000000, Resolution::TWO_K)); - shared_ptr remote (new DCPVideo (pvf, frame_count, film->video_frame_rate(), 250000000, Resolution::TWO_K)); + auto local = make_shared(pvf, frame_count, film->video_frame_rate(), 250000000, Resolution::TWO_K); + auto remote = make_shared(pvf, frame_count, film->video_frame_rate(), 250000000, Resolution::TWO_K); cout << "Frame " << frame_count << ": "; cout.flush (); ++frame_count; - ArrayData local_encoded = local->encode_locally (); + auto local_encoded = local->encode_locally (); ArrayData remote_encoded; string remote_error; @@ -73,7 +78,7 @@ process_video (shared_ptr pvf) remote_error = e.what (); } - if (!remote_error.empty ()) { + if (!remote_error.empty()) { cout << "\033[0;31mnetwork problem: " << remote_error << "\033[0m\n"; return; } @@ -83,8 +88,8 @@ process_video (shared_ptr pvf) return; } - uint8_t* p = local_encoded.data(); - uint8_t* q = remote_encoded.data(); + auto p = local_encoded.data(); + auto q = remote_encoded.data(); for (int i = 0; i < local_encoded.size(); ++i) { if (*p++ != *q++) { cout << "\033[0;31mdata differ\033[0m at byte " << i << "\n"; @@ -95,6 +100,7 @@ process_video (shared_ptr pvf) cout << "\033[0;32mgood\033[0m\n"; } + static void help (string n) { @@ -102,6 +108,7 @@ help (string n) exit (EXIT_FAILURE); } + int main (int argc, char* argv[]) { @@ -145,11 +152,11 @@ main (int argc, char* argv[]) try { server = new EncodeServerDescription (server_host, 1, SERVER_LINK_VERSION); - film.reset (new Film (film_dir)); + film = make_shared(film_dir); film->read_metadata (); - shared_ptr player (new Player(film)); - player->Video.connect (bind (&process_video, _1)); + auto player = make_shared(film); + player->Video.connect (bind(&process_video, _1)); while (!player->pass ()) {} } catch (std::exception& e) { cerr << "Error: " << e.what() << "\n"; diff --git a/src/wx/cinema_dialog.cc b/src/wx/cinema_dialog.cc index e67fe77ed..0e684334f 100644 --- a/src/wx/cinema_dialog.cc +++ b/src/wx/cinema_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,53 +18,50 @@ */ + #include "cinema_dialog.h" #include "wx_util.h" #include "lib/dcpomatic_assert.h" #include "lib/util.h" -using std::string; -using std::vector; -using std::copy; + using std::back_inserter; -using std::list; +using std::copy; using std::cout; +using std::list; +using std::string; +using std::vector; using boost::bind; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif -static string -column (string s) -{ - return s; -} CinemaDialog::CinemaDialog (wxWindow* parent, wxString title, string name, list emails, string notes, int utc_offset_hour, int utc_offset_minute) : wxDialog (parent, wxID_ANY, title) { - wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); + auto overall_sizer = new wxBoxSizer (wxVERTICAL); SetSizer (overall_sizer); - wxGridBagSizer* sizer = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); + auto sizer = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); int r = 0; - add_label_to_sizer (sizer, this, _("Name"), true, wxGBPosition (r, 0)); - _name = new wxTextCtrl (this, wxID_ANY, std_to_wx (name), wxDefaultPosition, wxSize (500, -1)); - sizer->Add (_name, wxGBPosition (r, 1)); + add_label_to_sizer (sizer, this, _("Name"), true, wxGBPosition(r, 0)); + _name = new wxTextCtrl (this, wxID_ANY, std_to_wx(name), wxDefaultPosition, wxSize(500, -1)); + sizer->Add (_name, wxGBPosition(r, 1)); ++r; - add_label_to_sizer (sizer, this, _("UTC offset (time zone)"), true, wxGBPosition (r, 0)); + add_label_to_sizer (sizer, this, _("UTC offset (time zone)"), true, wxGBPosition(r, 0)); _utc_offset = new wxChoice (this, wxID_ANY); - sizer->Add (_utc_offset, wxGBPosition (r, 1)); + sizer->Add (_utc_offset, wxGBPosition(r, 1)); ++r; - add_label_to_sizer (sizer, this, _("Notes"), true, wxGBPosition (r, 0)); - _notes = new wxTextCtrl (this, wxID_ANY, std_to_wx (notes), wxDefaultPosition, wxSize (500, -1)); - sizer->Add (_notes, wxGBPosition (r, 1)); + add_label_to_sizer (sizer, this, _("Notes"), true, wxGBPosition(r, 0)); + _notes = new wxTextCtrl (this, wxID_ANY, std_to_wx(notes), wxDefaultPosition, wxSize(500, -1)); + sizer->Add (_notes, wxGBPosition(r, 1)); ++r; - add_label_to_sizer (sizer, this, _("Email addresses for KDM delivery"), false, wxGBPosition (r, 0), wxGBSpan (1, 2)); + add_label_to_sizer (sizer, this, _("Email addresses for KDM delivery"), false, wxGBPosition(r, 0), wxGBSpan(1, 2)); ++r; copy (emails.begin(), emails.end(), back_inserter (_emails)); @@ -72,15 +69,17 @@ CinemaDialog::CinemaDialog (wxWindow* parent, wxString title, string name, list< vector columns; columns.push_back (EditableListColumn(_("Address"))); _email_list = new EditableList ( - this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&column, _1) + this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), [](string s, int) { + return s; + } ); - sizer->Add (_email_list, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND); + sizer->Add (_email_list, wxGBPosition(r, 0), wxGBSpan(1, 2), wxEXPAND); ++r; overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER); - wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL); + auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL); if (buttons) { overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); } @@ -102,56 +101,63 @@ CinemaDialog::CinemaDialog (wxWindow* parent, wxString title, string name, list< _name->SetFocus (); } + string CinemaDialog::name () const { return wx_to_std (_name->GetValue()); } + void CinemaDialog::set_emails (vector e) { _emails = e; } + vector CinemaDialog::get_emails () const { return _emails; } + list CinemaDialog::emails () const { list e; - copy (_emails.begin(), _emails.end(), back_inserter (e)); + copy (_emails.begin(), _emails.end(), back_inserter(e)); return e; } + int CinemaDialog::utc_offset_hour () const { int const sel = _utc_offset->GetSelection(); - if (sel < 0 || sel > int (_offsets.size())) { + if (sel < 0 || sel > int(_offsets.size())) { return 0; } return _offsets[sel].hour; } + int CinemaDialog::utc_offset_minute () const { int const sel = _utc_offset->GetSelection(); - if (sel < 0 || sel > int (_offsets.size())) { + if (sel < 0 || sel > int(_offsets.size())) { return 0; } return _offsets[sel].minute; } + string CinemaDialog::notes () const { - return wx_to_std (_notes->GetValue ()); + return wx_to_std (_notes->GetValue()); } diff --git a/src/wx/cinema_dialog.h b/src/wx/cinema_dialog.h index d16b0ba9c..e0594b5d8 100644 --- a/src/wx/cinema_dialog.h +++ b/src/wx/cinema_dialog.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,13 +18,15 @@ */ -#include "table_dialog.h" + #include "editable_list.h" #include "email_dialog.h" +#include "table_dialog.h" #include #include #include + class CinemaDialog : public wxDialog { public: diff --git a/src/wx/dcp_panel.cc b/src/wx/dcp_panel.cc index aa3cf4b22..4421b81b2 100644 --- a/src/wx/dcp_panel.cc +++ b/src/wx/dcp_panel.cc @@ -18,6 +18,7 @@ */ + #include "audio_dialog.h" #include "check_box.h" #include "check_box.h" @@ -49,6 +50,7 @@ #include #include + using std::cout; using std::list; using std::string; @@ -64,12 +66,9 @@ using namespace boost::placeholders; #endif using dcp::locale_convert; + DCPPanel::DCPPanel (wxNotebook* n, shared_ptr film, weak_ptr viewer) - : _audio_dialog (0) - , _markers_dialog (0) - , _interop_metadata_dialog (0) - , _smpte_metadata_dialog (0) - , _film (film) + : _film (film) , _viewer (viewer) , _generally_sensitive (true) { @@ -123,19 +122,19 @@ DCPPanel::DCPPanel (wxNotebook* n, shared_ptr film, weak_ptr v _notebook->AddPage (make_video_panel (), _("Video"), false); _notebook->AddPage (make_audio_panel (), _("Audio"), false); - _name->Bind (wxEVT_TEXT, boost::bind (&DCPPanel::name_changed, this)); - _use_isdcf_name->Bind (wxEVT_CHECKBOX, boost::bind (&DCPPanel::use_isdcf_name_toggled, this)); - _copy_isdcf_name_button->Bind(wxEVT_BUTTON, boost::bind (&DCPPanel::copy_isdcf_name_button_clicked, this)); - _dcp_content_type->Bind (wxEVT_CHOICE, boost::bind (&DCPPanel::dcp_content_type_changed, this)); - _encrypted->Bind (wxEVT_CHECKBOX, boost::bind (&DCPPanel::encrypted_toggled, this)); - _reel_type->Bind (wxEVT_CHOICE, boost::bind (&DCPPanel::reel_type_changed, this)); - _reel_length->Bind (wxEVT_SPINCTRL, boost::bind (&DCPPanel::reel_length_changed, this)); - _standard->Bind (wxEVT_CHOICE, boost::bind (&DCPPanel::standard_changed, this)); - _markers->Bind (wxEVT_BUTTON, boost::bind (&DCPPanel::markers_clicked, this)); - _metadata->Bind (wxEVT_BUTTON, boost::bind (&DCPPanel::metadata_clicked, this)); + _name->Bind (wxEVT_TEXT, boost::bind(&DCPPanel::name_changed, this)); + _use_isdcf_name->Bind (wxEVT_CHECKBOX, boost::bind(&DCPPanel::use_isdcf_name_toggled, this)); + _copy_isdcf_name_button->Bind(wxEVT_BUTTON, boost::bind(&DCPPanel::copy_isdcf_name_button_clicked, this)); + _dcp_content_type->Bind (wxEVT_CHOICE, boost::bind(&DCPPanel::dcp_content_type_changed, this)); + _encrypted->Bind (wxEVT_CHECKBOX, boost::bind(&DCPPanel::encrypted_toggled, this)); + _reel_type->Bind (wxEVT_CHOICE, boost::bind(&DCPPanel::reel_type_changed, this)); + _reel_length->Bind (wxEVT_SPINCTRL, boost::bind(&DCPPanel::reel_length_changed, this)); + _standard->Bind (wxEVT_CHOICE, boost::bind(&DCPPanel::standard_changed, this)); + _markers->Bind (wxEVT_BUTTON, boost::bind(&DCPPanel::markers_clicked, this)); + _metadata->Bind (wxEVT_BUTTON, boost::bind(&DCPPanel::metadata_clicked, this)); for (auto i: DCPContentType::all()) { - _dcp_content_type->Append (std_to_wx (i->pretty_name ())); + _dcp_content_type->Append (std_to_wx(i->pretty_name())); } _reel_type->Append (_("Single reel")); @@ -148,7 +147,7 @@ DCPPanel::DCPPanel (wxNotebook* n, shared_ptr film, weak_ptr v _standard->Append (_("SMPTE")); _standard->Append (_("Interop")); - Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this, _1)); + Config::instance()->Changed.connect (boost::bind(&DCPPanel::config_changed, this, _1)); add_to_grid (); } @@ -169,39 +168,39 @@ DCPPanel::add_to_grid () flags |= wxALIGN_RIGHT; #endif - _grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags); + _grid->Add (_use_isdcf_name, wxGBPosition(r, 0), wxDefaultSpan, flags); { auto s = new wxBoxSizer (wxHORIZONTAL); s->Add (_copy_isdcf_name_button, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP); - _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND); + _grid->Add (s, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND); } ++r; _grid->Add (_dcp_name, wxGBPosition(r, 0), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL | wxEXPAND); ++r; - add_label_to_sizer (_grid, _dcp_content_type_label, true, wxGBPosition (r, 0)); - _grid->Add (_dcp_content_type, wxGBPosition (r, 1)); + add_label_to_sizer (_grid, _dcp_content_type_label, true, wxGBPosition(r, 0)); + _grid->Add (_dcp_content_type, wxGBPosition(r, 1)); ++r; - _grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2)); + _grid->Add (_encrypted, wxGBPosition(r, 0), wxGBSpan(1, 2)); ++r; - add_label_to_sizer (_grid, _reels_label, true, wxGBPosition (r, 0)); - _grid->Add (_reel_type, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); + add_label_to_sizer (_grid, _reels_label, true, wxGBPosition(r, 0)); + _grid->Add (_reel_type, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); ++r; - add_label_to_sizer (_grid, _reel_length_label, true, wxGBPosition (r, 0)); + add_label_to_sizer (_grid, _reel_length_label, true, wxGBPosition(r, 0)); { - wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL); + auto s = new wxBoxSizer (wxHORIZONTAL); s->Add (_reel_length); add_label_to_sizer (s, _reel_length_gb_label, false, 0, wxLEFT | wxALIGN_CENTER_VERTICAL); - _grid->Add (s, wxGBPosition (r, 1)); + _grid->Add (s, wxGBPosition(r, 1)); } ++r; - add_label_to_sizer (_grid, _standard_label, true, wxGBPosition (r, 0)); - _grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); + add_label_to_sizer (_grid, _standard_label, true, wxGBPosition(r, 0)); + _grid->Add (_standard, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); ++r; auto extra = new wxBoxSizer (wxHORIZONTAL); @@ -211,6 +210,7 @@ DCPPanel::add_to_grid () ++r; } + void DCPPanel::name_changed () { @@ -218,9 +218,10 @@ DCPPanel::name_changed () return; } - _film->set_name (string (_name->GetValue().mb_str())); + _film->set_name (string(_name->GetValue().mb_str())); } + void DCPPanel::j2k_bandwidth_changed () { @@ -231,6 +232,7 @@ DCPPanel::j2k_bandwidth_changed () _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000); } + void DCPPanel::encrypted_toggled () { @@ -238,9 +240,10 @@ DCPPanel::encrypted_toggled () return; } - _film->set_encrypted (_encrypted->GetValue ()); + _film->set_encrypted (_encrypted->GetValue()); } + /** Called when the frame rate choice widget has been changed */ void DCPPanel::frame_rate_choice_changed () @@ -257,6 +260,7 @@ DCPPanel::frame_rate_choice_changed () ); } + /** Called when the frame rate spin widget has been changed */ void DCPPanel::frame_rate_spin_changed () @@ -265,9 +269,10 @@ DCPPanel::frame_rate_spin_changed () return; } - _film->set_video_frame_rate (_frame_rate_spin->GetValue ()); + _film->set_video_frame_rate (_frame_rate_spin->GetValue()); } + void DCPPanel::audio_channels_changed () { @@ -275,9 +280,10 @@ DCPPanel::audio_channels_changed () return; } - _film->set_audio_channels (locale_convert (string_client_data (_audio_channels->GetClientObject (_audio_channels->GetSelection ())))); + _film->set_audio_channels (locale_convert(string_client_data(_audio_channels->GetClientObject(_audio_channels->GetSelection())))); } + void DCPPanel::resolution_changed () { @@ -288,6 +294,7 @@ DCPPanel::resolution_changed () _film->set_resolution (_resolution->GetSelection() == 0 ? Resolution::TWO_K : Resolution::FOUR_K); } + void DCPPanel::standard_changed () { @@ -296,6 +303,7 @@ DCPPanel::standard_changed () } _film->set_interop (_standard->GetSelection() == 1); + } void @@ -303,20 +311,21 @@ DCPPanel::markers_clicked () { if (_markers_dialog) { _markers_dialog->Destroy (); - _markers_dialog = 0; + _markers_dialog = nullptr; } _markers_dialog = new MarkersDialog (_panel, _film, _viewer); _markers_dialog->Show(); } + void DCPPanel::metadata_clicked () { if (_film->interop()) { if (_interop_metadata_dialog) { _interop_metadata_dialog->Destroy (); - _interop_metadata_dialog = 0; + _interop_metadata_dialog = nullptr; } _interop_metadata_dialog = new InteropMetadataDialog (_panel, _film); @@ -325,7 +334,7 @@ DCPPanel::metadata_clicked () } else { if (_smpte_metadata_dialog) { _smpte_metadata_dialog->Destroy (); - _smpte_metadata_dialog = 0; + _smpte_metadata_dialog = nullptr; } _smpte_metadata_dialog = new SMPTEMetadataDialog (_panel, _film); @@ -334,6 +343,7 @@ DCPPanel::metadata_clicked () } } + void DCPPanel::film_changed (Film::Property p) { @@ -348,9 +358,13 @@ DCPPanel::film_changed (Film::Property p) setup_dcp_name (); break; case Film::Property::DCP_CONTENT_TYPE: - checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ())); + { + auto index = DCPContentType::as_index(_film->dcp_content_type()); + DCPOMATIC_ASSERT (index); + checked_set (_dcp_content_type, *index); setup_dcp_name (); break; + } case Film::Property::ENCRYPTED: checked_set (_encrypted, _film->encrypted ()); break; @@ -364,7 +378,7 @@ DCPPanel::film_changed (Film::Property p) break; case Film::Property::USE_ISDCF_NAME: { - checked_set (_use_isdcf_name, _film->use_isdcf_name ()); + checked_set (_use_isdcf_name, _film->use_isdcf_name()); if (_film->use_isdcf_name()) { /* We are going back to using an ISDCF name. Remove anything after a _ in the current name, in case the user has clicked 'Copy as name' then re-ticked 'Use ISDCF name' (#1513). @@ -382,7 +396,7 @@ DCPPanel::film_changed (Film::Property p) { bool done = false; for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) { - if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast (_film->video_frame_rate())) { + if (wx_to_std(_frame_rate_choice->GetString(i)) == boost::lexical_cast(_film->video_frame_rate())) { checked_set (_frame_rate_choice, i); done = true; break; @@ -400,15 +414,15 @@ DCPPanel::film_changed (Film::Property p) break; } case Film::Property::AUDIO_CHANNELS: - if (_film->audio_channels () < minimum_allowed_audio_channels ()) { - _film->set_audio_channels (minimum_allowed_audio_channels ()); + if (_film->audio_channels() < minimum_allowed_audio_channels()) { + _film->set_audio_channels (minimum_allowed_audio_channels()); } else { - checked_set (_audio_channels, locale_convert (max (minimum_allowed_audio_channels(), _film->audio_channels ()))); + checked_set (_audio_channels, locale_convert(max(minimum_allowed_audio_channels(), _film->audio_channels()))); setup_dcp_name (); } break; case Film::Property::THREE_D: - checked_set (_three_d, _film->three_d ()); + checked_set (_three_d, _film->three_d()); setup_dcp_name (); break; case Film::Property::REENCODE_J2K: @@ -420,12 +434,12 @@ DCPPanel::film_changed (Film::Property p) _markers->Enable (!_film->interop()); break; case Film::Property::AUDIO_PROCESSOR: - if (_film->audio_processor ()) { + if (_film->audio_processor()) { checked_set (_audio_processor, _film->audio_processor()->id()); } else { checked_set (_audio_processor, 0); } - setup_audio_channels_choice (_audio_channels, minimum_allowed_audio_channels ()); + setup_audio_channels_choice (_audio_channels, minimum_allowed_audio_channels()); film_changed (Film::Property::AUDIO_CHANNELS); break; case Film::Property::REEL_TYPE: @@ -458,6 +472,7 @@ DCPPanel::film_changed (Film::Property p) } } + void DCPPanel::film_content_changed (int property) { @@ -482,25 +497,26 @@ void DCPPanel::setup_container () { int n = 0; - vector ratios = Ratio::containers (); - vector::iterator i = ratios.begin (); - while (i != ratios.end() && *i != _film->container ()) { + auto ratios = Ratio::containers (); + auto i = ratios.begin (); + while (i != ratios.end() && *i != _film->container()) { ++i; ++n; } if (i == ratios.end()) { checked_set (_container, -1); - checked_set (_container_size, wxT ("")); + checked_set (_container_size, wxT("")); } else { checked_set (_container, n); - dcp::Size const size = fit_ratio_within (_film->container()->ratio(), _film->full_frame ()); - checked_set (_container_size, wxString::Format ("%dx%d", size.width, size.height)); + auto const size = fit_ratio_within (_film->container()->ratio(), _film->full_frame ()); + checked_set (_container_size, wxString::Format("%dx%d", size.width, size.height)); } setup_dcp_name (); } + /** Called when the container widget has been changed */ void DCPPanel::container_changed () @@ -511,12 +527,13 @@ DCPPanel::container_changed () int const n = _container->GetSelection (); if (n >= 0) { - vector ratios = Ratio::containers (); - DCPOMATIC_ASSERT (n < int (ratios.size())); + auto ratios = Ratio::containers (); + DCPOMATIC_ASSERT (n < int(ratios.size())); _film->set_container (ratios[n]); } } + /** Called when the DCP content type widget has been changed */ void DCPPanel::dcp_content_type_changed () @@ -527,10 +544,11 @@ DCPPanel::dcp_content_type_changed () int const n = _dcp_content_type->GetSelection (); if (n != wxNOT_FOUND) { - _film->set_dcp_content_type (DCPContentType::from_index (n)); + _film->set_dcp_content_type (DCPContentType::from_index(n)); } } + void DCPPanel::set_film (shared_ptr film) { @@ -582,6 +600,7 @@ DCPPanel::set_film (shared_ptr film) set_general_sensitivity(static_cast(_film)); } + void DCPPanel::set_general_sensitivity (bool s) { @@ -589,6 +608,7 @@ DCPPanel::set_general_sensitivity (bool s) setup_sensitivity (); } + void DCPPanel::setup_sensitivity () { @@ -629,6 +649,7 @@ DCPPanel::setup_sensitivity () _show_audio->Enable (_generally_sensitive && _film); } + void DCPPanel::use_isdcf_name_toggled () { @@ -636,16 +657,17 @@ DCPPanel::use_isdcf_name_toggled () return; } - _film->set_use_isdcf_name (_use_isdcf_name->GetValue ()); + _film->set_use_isdcf_name (_use_isdcf_name->GetValue()); } void DCPPanel::setup_dcp_name () { - _dcp_name->SetLabel (std_to_wx (_film->dcp_name (true))); - _dcp_name->SetToolTip (std_to_wx (_film->dcp_name (true))); + _dcp_name->SetLabel (std_to_wx(_film->dcp_name(true))); + _dcp_name->SetToolTip (std_to_wx(_film->dcp_name(true))); } + void DCPPanel::best_frame_rate_clicked () { @@ -653,9 +675,10 @@ DCPPanel::best_frame_rate_clicked () return; } - _film->set_video_frame_rate (_film->best_video_frame_rate ()); + _film->set_video_frame_rate (_film->best_video_frame_rate()); } + void DCPPanel::three_d_changed () { @@ -663,9 +686,10 @@ DCPPanel::three_d_changed () return; } - _film->set_three_d (_three_d->GetValue ()); + _film->set_three_d (_three_d->GetValue()); } + void DCPPanel::reencode_j2k_changed () { @@ -676,6 +700,7 @@ DCPPanel::reencode_j2k_changed () _film->set_reencode_j2k (_reencode_j2k->GetValue()); } + void DCPPanel::config_changed (Config::Property p) { @@ -691,10 +716,11 @@ DCPPanel::config_changed (Config::Property p) } } + void DCPPanel::setup_frame_rate_widget () { - if (Config::instance()->allow_any_dcp_frame_rate ()) { + if (Config::instance()->allow_any_dcp_frame_rate()) { _frame_rate_choice->Hide (); _frame_rate_spin->Show (); } else { @@ -703,6 +729,7 @@ DCPPanel::setup_frame_rate_widget () } } + wxPanel * DCPPanel::make_video_panel () { @@ -769,6 +796,7 @@ DCPPanel::make_video_panel () return panel; } + void DCPPanel::add_video_panel_to_grid () { @@ -776,7 +804,7 @@ DCPPanel::add_video_panel_to_grid () add_label_to_sizer (_video_grid, _container_label, true, wxGBPosition (r, 0)); { - wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL); + auto s = new wxBoxSizer (wxHORIZONTAL); s->Add (_container, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP); s->Add (_container_size, 1, wxLEFT | wxALIGN_CENTER_VERTICAL); _video_grid->Add (s, wxGBPosition(r, 1)); @@ -809,6 +837,7 @@ DCPPanel::add_video_panel_to_grid () _video_grid->Add (_reencode_j2k, wxGBPosition(r, 0), wxGBSpan(1, 2)); } + int DCPPanel::minimum_allowed_audio_channels () const { @@ -824,6 +853,7 @@ DCPPanel::minimum_allowed_audio_channels () const return min; } + wxPanel * DCPPanel::make_audio_panel () { @@ -852,6 +882,7 @@ DCPPanel::make_audio_panel () return panel; } + void DCPPanel::add_audio_panel_to_grid () { @@ -869,6 +900,7 @@ DCPPanel::add_audio_panel_to_grid () ++r; } + void DCPPanel::copy_isdcf_name_button_clicked () { @@ -876,6 +908,7 @@ DCPPanel::copy_isdcf_name_button_clicked () _film->set_use_isdcf_name (false); } + void DCPPanel::audio_processor_changed () { @@ -887,6 +920,7 @@ DCPPanel::audio_processor_changed () _film->set_audio_processor (AudioProcessor::from_id (s)); } + void DCPPanel::show_audio_clicked () { @@ -903,6 +937,7 @@ DCPPanel::show_audio_clicked () d->Show (); } + void DCPPanel::reel_type_changed () { @@ -910,9 +945,10 @@ DCPPanel::reel_type_changed () return; } - _film->set_reel_type (static_cast (_reel_type->GetSelection ())); + _film->set_reel_type (static_cast(_reel_type->GetSelection())); } + void DCPPanel::reel_length_changed () { @@ -923,10 +959,11 @@ DCPPanel::reel_length_changed () _film->set_reel_length (_reel_length->GetValue() * 1000000000LL); } + void DCPPanel::add_audio_processors () { - _audio_processor->Append (_("None"), new wxStringClientData (N_("none"))); + _audio_processor->Append (_("None"), new wxStringClientData(N_("none"))); for (auto ap: AudioProcessor::visible()) { _audio_processor->Append (std_to_wx(ap->name()), new wxStringClientData(std_to_wx(ap->id()))); } diff --git a/src/wx/dcp_panel.h b/src/wx/dcp_panel.h index a076e4bb4..dc5e9bcbf 100644 --- a/src/wx/dcp_panel.h +++ b/src/wx/dcp_panel.h @@ -43,6 +43,7 @@ class Film; class FilmViewer; class Ratio; + class DCPPanel { public: @@ -149,10 +150,10 @@ private: wxButton* _metadata; wxSizer* _audio_panel_sizer; - AudioDialog* _audio_dialog; - MarkersDialog* _markers_dialog; - InteropMetadataDialog* _interop_metadata_dialog; - SMPTEMetadataDialog* _smpte_metadata_dialog; + AudioDialog* _audio_dialog = nullptr; + MarkersDialog* _markers_dialog = nullptr; + InteropMetadataDialog* _interop_metadata_dialog = nullptr; + SMPTEMetadataDialog* _smpte_metadata_dialog = nullptr; std::shared_ptr _film; std::weak_ptr _viewer; diff --git a/src/wx/file_dialog_wrapper.h b/src/wx/file_dialog_wrapper.h index dd63ff2da..8223371db 100644 --- a/src/wx/file_dialog_wrapper.h +++ b/src/wx/file_dialog_wrapper.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,8 +18,11 @@ */ + +#include "wx_util.h" #include + template class FileDialogWrapper { @@ -34,7 +37,7 @@ public: boost::optional get () { - return T (dcp::file_to_string (wx_to_std (_dialog->GetPath ()))); + return T (dcp::file_to_string(wx_to_std(_dialog->GetPath()))); } int ShowModal () diff --git a/src/wx/filter_dialog.cc b/src/wx/filter_dialog.cc index a65f5153a..3dbb48236 100644 --- a/src/wx/filter_dialog.cc +++ b/src/wx/filter_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,10 +18,12 @@ */ + /** @file src/filter_dialog.cc * @brief A dialog to select FFmpeg filters. */ + #include "check_box.h" #include "filter_dialog.h" #include "static_text.h" @@ -37,35 +39,31 @@ using boost::bind; FilterDialog::FilterDialog (wxWindow* parent, vector const & active) : wxDialog (parent, wxID_ANY, wxString(_("Filters"))) { - wxPanel* panel = new wxPanel (this); - wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL); + auto panel = new wxPanel (this); + auto sizer = new wxBoxSizer (wxVERTICAL); - vector filters = Filter::all (); + auto filters = Filter::all (); - typedef map > CategoryMap; - CategoryMap categories; + map> categories; for (auto i: filters) { - CategoryMap::iterator j = categories.find (i->category()); + auto j = categories.find (i->category()); if (j == categories.end ()) { - list c; - c.push_back (i); - categories[i->category()] = c; + categories[i->category()] = { i }; } else { j->second.push_back (i); } } - for (CategoryMap::iterator i = categories.begin(); i != categories.end(); ++i) { - - wxStaticText* c = new StaticText (panel, std_to_wx(i->first)); - wxFont font = c->GetFont(); + for (auto const& i: categories) { + auto c = new StaticText (panel, std_to_wx(i.first)); + auto font = c->GetFont(); font.SetWeight(wxFONTWEIGHT_BOLD); c->SetFont(font); sizer->Add (c, 1, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP); - for (auto j: i->second) { - wxCheckBox* b = new CheckBox(panel, std_to_wx(j->name())); + for (auto j: i.second) { + auto b = new CheckBox(panel, std_to_wx(j->name())); bool const a = find (active.begin(), active.end(), j) != active.end(); b->SetValue (a); _filters[j] = b; @@ -76,14 +74,14 @@ FilterDialog::FilterDialog (wxWindow* parent, vector const & act sizer->AddSpacer (6); } - wxSizer* buttons = CreateSeparatedButtonSizer (wxOK); + auto buttons = CreateSeparatedButtonSizer (wxOK); if (buttons) { sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); } panel->SetSizer (sizer); - wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); + auto overall_sizer = new wxBoxSizer (wxVERTICAL); overall_sizer->Add (panel, 1, wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP); SetSizerAndFit (overall_sizer); } @@ -100,9 +98,9 @@ vector FilterDialog::active () const { vector active; - for (map::const_iterator i = _filters.begin(); i != _filters.end(); ++i) { - if (i->second->IsChecked()) { - active.push_back(i->first); + for (auto const& i: _filters) { + if (i.second->IsChecked()) { + active.push_back(i.first); } } diff --git a/src/wx/filter_dialog.h b/src/wx/filter_dialog.h index 775995f38..33f92c0a6 100644 --- a/src/wx/filter_dialog.h +++ b/src/wx/filter_dialog.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,19 +18,23 @@ */ + /** @file src/filter_dialog.h * @brief A dialog to select FFmpeg filters. */ + #include "lib/warnings.h" DCPOMATIC_DISABLE_WARNINGS #include DCPOMATIC_ENABLE_WARNINGS #include + class Film; class Filter; + /** @class FilterDialog * @brief A dialog to select FFmpeg filters. */ diff --git a/src/wx/fonts_dialog.cc b/src/wx/fonts_dialog.cc index 29af6a739..e61055ad7 100644 --- a/src/wx/fonts_dialog.cc +++ b/src/wx/fonts_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2018 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "fonts_dialog.h" #include "wx_util.h" #include "system_font_dialog.h" @@ -28,12 +29,14 @@ #include #include + using std::list; using std::string; using std::cout; using std::shared_ptr; using namespace dcpomatic; + FontsDialog::FontsDialog (wxWindow* parent, shared_ptr content, shared_ptr caption) : wxDialog (parent, wxID_ANY, _("Fonts")) , _content (content) @@ -57,16 +60,16 @@ FontsDialog::FontsDialog (wxWindow* parent, shared_ptr content, shared_ _fonts->InsertColumn (1, ip); } - wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL); + auto sizer = new wxBoxSizer (wxHORIZONTAL); sizer->Add (_fonts, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP); _edit = new Button (this, _("Edit...")); sizer->Add (_edit, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); - wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); + auto overall_sizer = new wxBoxSizer (wxVERTICAL); overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP); - wxSizer* buttons = CreateSeparatedButtonSizer (wxOK); + auto buttons = CreateSeparatedButtonSizer (wxOK); if (buttons) { overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); } @@ -80,11 +83,12 @@ FontsDialog::FontsDialog (wxWindow* parent, shared_ptr content, shared_ setup (); } + void FontsDialog::setup () { - shared_ptr content = _content.lock (); - shared_ptr caption = _caption.lock (); + auto content = _content.lock (); + auto caption = _caption.lock (); if (!content || !caption) { return; } @@ -105,12 +109,14 @@ FontsDialog::setup () setup_sensitivity (); } + void FontsDialog::selection_changed () { setup_sensitivity (); } + void FontsDialog::setup_sensitivity () { @@ -118,17 +124,18 @@ FontsDialog::setup_sensitivity () _edit->Enable (item != -1); } + void FontsDialog::edit_clicked () { - shared_ptr content = _content.lock (); - shared_ptr caption = _caption.lock (); + auto content = _content.lock (); + auto caption = _caption.lock (); if (!content || !caption) { return; } int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - string const id = wx_to_std (_fonts->GetItemText (item, 0)); + auto const id = wx_to_std (_fonts->GetItemText(item, 0)); shared_ptr font; for (auto i: caption->fonts()) { if (i->id() == id) { @@ -155,7 +162,7 @@ FontsDialog::edit_clicked () default_dir = "/System/Library/Fonts"; #endif - wxFileDialog* d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT(""), wxT("*.ttf;*.otf"), wxFD_CHANGE_DIR); + auto d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT(""), wxT("*.ttf;*.otf"), wxFD_CHANGE_DIR); int const r = d->ShowModal (); if (r != wxID_OK) { diff --git a/src/wx/fonts_dialog.h b/src/wx/fonts_dialog.h index 0ef3658cf..a77684cb9 100644 --- a/src/wx/fonts_dialog.h +++ b/src/wx/fonts_dialog.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2018 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "lib/warnings.h" DCPOMATIC_DISABLE_WARNINGS #include @@ -25,9 +26,11 @@ DCPOMATIC_DISABLE_WARNINGS DCPOMATIC_ENABLE_WARNINGS #include + class Content; class TextContent; + class FontsDialog : public wxDialog { public: diff --git a/src/wx/i18n_hook.cc b/src/wx/i18n_hook.cc index 827e81bc9..f6b963622 100644 --- a/src/wx/i18n_hook.cc +++ b/src/wx/i18n_hook.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018-2019 Carl Hetherington + Copyright (C) 2018-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "i18n_hook.h" #include "instant_i18n_dialog.h" #include "wx_util.h" @@ -25,6 +26,7 @@ #include #include + using std::map; using std::string; #if BOOST_VERSION >= 106100 @@ -41,15 +43,16 @@ I18NHook::I18NHook (wxWindow* window, wxString original) _window->Bind (wxEVT_MIDDLE_DOWN, bind(&I18NHook::handle, this, _1)); } + void I18NHook::handle (wxMouseEvent& ev) { - InstantI18NDialog* d = new InstantI18NDialog (_window, get_text()); + auto d = new InstantI18NDialog (_window, get_text()); d->ShowModal(); set_text (d->get()); d->Destroy (); - wxWindow* w = _window; + auto w = _window; while (w) { if (w->GetContainingSizer()) { w->GetContainingSizer()->Layout(); diff --git a/src/wx/i18n_hook.h b/src/wx/i18n_hook.h index b2de66172..bb1bc8227 100644 --- a/src/wx/i18n_hook.h +++ b/src/wx/i18n_hook.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2018-2019 Carl Hetherington + Copyright (C) 2018-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,15 +18,18 @@ */ + #ifndef DCPOMATIC_I18N_HOOK_H #define DCPOMATIC_I18N_HOOK_H + #include "lib/warnings.h" DCPOMATIC_DISABLE_WARNINGS #include DCPOMATIC_ENABLE_WARNINGS #include + class I18NHook { public: @@ -48,4 +51,5 @@ private: static std::map _translations; }; + #endif diff --git a/src/wx/screen_dialog.cc b/src/wx/screen_dialog.cc index 030098920..8da8f061e 100644 --- a/src/wx/screen_dialog.cc +++ b/src/wx/screen_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,13 +18,14 @@ */ -#include "screen_dialog.h" -#include "wx_util.h" + +#include "dcpomatic_button.h" +#include "download_certificate_dialog.h" #include "file_dialog_wrapper.h" +#include "screen_dialog.h" #include "static_text.h" -#include "download_certificate_dialog.h" #include "table_dialog.h" -#include "dcpomatic_button.h" +#include "wx_util.h" #include "lib/compose.hpp" #include "lib/util.h" #include "lib/warnings.h" @@ -36,6 +37,7 @@ DCPOMATIC_DISABLE_WARNINGS DCPOMATIC_ENABLE_WARNINGS #include + using std::string; using std::cout; using std::vector; @@ -45,11 +47,6 @@ using boost::bind; using namespace boost::placeholders; #endif -static string -column (TrustedDevice d) -{ - return d.thumbprint (); -} class TrustedDeviceDialog : public TableDialog { @@ -68,7 +65,7 @@ public: void load_certificate () { - wxFileDialog* d = new wxFileDialog (this, _("Trusted Device certificate")); + auto d = new wxFileDialog (this, _("Trusted Device certificate")); if (d->ShowModal() == wxID_OK) { try { _certificate = dcp::Certificate(dcp::file_to_string(wx_to_std(d->GetPath()))); @@ -87,14 +84,14 @@ public: optional get () { - string const t = wx_to_std (_thumbprint->GetValue ()); + auto const t = wx_to_std (_thumbprint->GetValue()); if (_certificate && _certificate->thumbprint() == t) { return TrustedDevice (*_certificate); } else if (t.length() == 28) { return TrustedDevice (t); } - return optional (); + return {}; } private: @@ -103,6 +100,7 @@ private: boost::optional _certificate; }; + ScreenDialog::ScreenDialog ( wxWindow* parent, wxString title, string name, string notes, optional recipient, vector trusted_devices ) @@ -110,30 +108,30 @@ ScreenDialog::ScreenDialog ( , _recipient (recipient) , _trusted_devices (trusted_devices) { - wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); + auto overall_sizer = new wxBoxSizer (wxVERTICAL); SetSizer (overall_sizer); _sizer = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); int r = 0; - add_label_to_sizer (_sizer, this, _("Name"), true, wxGBPosition (r, 0)); + add_label_to_sizer (_sizer, this, _("Name"), true, wxGBPosition(r, 0)); _name = new wxTextCtrl (this, wxID_ANY, std_to_wx (name), wxDefaultPosition, wxSize (320, -1)); _sizer->Add (_name, wxGBPosition (r, 1)); ++r; - add_label_to_sizer (_sizer, this, _("Notes"), true, wxGBPosition (r, 0)); - _notes = new wxTextCtrl (this, wxID_ANY, std_to_wx (notes), wxDefaultPosition, wxSize (320, -1)); - _sizer->Add (_notes, wxGBPosition (r, 1)); + add_label_to_sizer (_sizer, this, _("Notes"), true, wxGBPosition(r, 0)); + _notes = new wxTextCtrl (this, wxID_ANY, std_to_wx(notes), wxDefaultPosition, wxSize(320, -1)); + _sizer->Add (_notes, wxGBPosition(r, 1)); ++r; wxClientDC dc (this); wxFont font = _name->GetFont (); font.SetFamily (wxFONTFAMILY_TELETYPE); dc.SetFont (font); - wxSize size = dc.GetTextExtent (wxT ("1234567890123456789012345678")); + wxSize size = dc.GetTextExtent (wxT("1234567890123456789012345678")); size.SetHeight (-1); - add_label_to_sizer (_sizer, this, _("Recipient certificate"), true, wxGBPosition (r, 0)); + add_label_to_sizer (_sizer, this, _("Recipient certificate"), true, wxGBPosition(r, 0)); wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL); _recipient_thumbprint = new StaticText (this, wxT (""), wxDefaultPosition, size); _recipient_thumbprint->SetFont (font); @@ -156,7 +154,9 @@ ScreenDialog::ScreenDialog ( columns, bind (&ScreenDialog::trusted_devices, this), bind (&ScreenDialog::set_trusted_devices, this, _1), - bind (&column, _1), + [] (TrustedDevice const& d, int) { + return d.thumbprint(); + }, false ); @@ -180,30 +180,34 @@ ScreenDialog::ScreenDialog ( setup_sensitivity (); } + string ScreenDialog::name () const { return wx_to_std (_name->GetValue()); } + string ScreenDialog::notes () const { return wx_to_std (_notes->GetValue()); } + optional ScreenDialog::recipient () const { return _recipient; } + void ScreenDialog::load_recipient (boost::filesystem::path file) { try { /* Load this as a chain, in case it is one, and then pick the leaf certificate */ - dcp::CertificateChain c (dcp::file_to_string (file)); + dcp::CertificateChain c (dcp::file_to_string(file)); if (c.unordered().empty()) { error_dialog (this, _("Could not read certificate file.")); return; @@ -214,38 +218,42 @@ ScreenDialog::load_recipient (boost::filesystem::path file) } } + void ScreenDialog::get_recipient_from_file () { - wxFileDialog* d = new wxFileDialog (this, _("Select Certificate File")); - if (d->ShowModal () == wxID_OK) { - load_recipient (boost::filesystem::path (wx_to_std (d->GetPath ()))); + auto d = new wxFileDialog (this, _("Select Certificate File")); + if (d->ShowModal() == wxID_OK) { + load_recipient (boost::filesystem::path(wx_to_std(d->GetPath()))); } d->Destroy (); setup_sensitivity (); } + void ScreenDialog::download_recipient () { - DownloadCertificateDialog* d = new DownloadCertificateDialog (this); + auto d = new DownloadCertificateDialog (this); if (d->ShowModal() == wxID_OK) { - set_recipient (d->certificate ()); + set_recipient (d->certificate()); } d->Destroy (); setup_sensitivity (); } + void ScreenDialog::setup_sensitivity () { - wxButton* ok = dynamic_cast (FindWindowById (wxID_OK, this)); + auto ok = dynamic_cast (FindWindowById(wxID_OK, this)); if (ok) { ok->Enable (static_cast(_recipient) && !_name->GetValue().IsEmpty()); } } + void ScreenDialog::set_recipient (optional r) { diff --git a/src/wx/screen_dialog.h b/src/wx/screen_dialog.h index 6665ef398..2c2d8b8bf 100644 --- a/src/wx/screen_dialog.h +++ b/src/wx/screen_dialog.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,15 +18,18 @@ */ + #include "editable_list.h" #include "lib/screen.h" #include #include #include + class Progress; class TrustedDeviceDialog; + class ScreenDialog : public wxDialog { public: @@ -35,7 +38,7 @@ public: wxString, std::string name = "", std::string notes = "", - boost::optional c = boost::optional (), + boost::optional c = boost::optional(), std::vector d = std::vector() ); diff --git a/src/wx/system_font_dialog.cc b/src/wx/system_font_dialog.cc index 6a98ecec6..df5b8e21b 100644 --- a/src/wx/system_font_dialog.cc +++ b/src/wx/system_font_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,42 +18,40 @@ */ + #include "system_font_dialog.h" #include "wx_util.h" #include #include #include + using std::cout; using std::string; using boost::optional; + SystemFontDialog::SystemFontDialog (wxWindow* parent) : wxDialog (parent, wxID_ANY, _("Choose a font")) { - wxSizer* sizer = new wxBoxSizer (wxVERTICAL); + auto sizer = new wxBoxSizer (wxVERTICAL); boost::filesystem::path fonts = "c:\\Windows\\Fonts"; - char* windir = getenv ("windir"); + auto windir = getenv ("windir"); if (windir) { fonts = boost::filesystem::path (windir) / "Fonts"; } - for ( - boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (fonts); - i != boost::filesystem::directory_iterator (); - ++i - ) { - - string ext = i->path().extension().string (); + for (auto i: boost::filesystem::directory_iterator (fonts)) { + auto ext = i.path().extension().string(); transform (ext.begin(), ext.end(), ext.begin(), ::tolower); if (ext == ".ttf") { - _fonts.push_back (i->path()); + _fonts.push_back (i.path()); } } - sort (_fonts.begin (), _fonts.end ()); + sort (_fonts.begin(), _fonts.end()); _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER); _list->InsertColumn (0, wxT ("")); @@ -65,7 +63,7 @@ SystemFontDialog::SystemFontDialog (wxWindow* parent) _list->InsertItem (n++, std_to_wx (i.leaf().stem().string ())); } - wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL); + auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL); if (buttons) { sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); } @@ -78,25 +76,27 @@ SystemFontDialog::SystemFontDialog (wxWindow* parent) setup_sensitivity (); } + optional SystemFontDialog::get_font () const { int const s = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (s == -1) { - return optional (); + return {}; } - if (s < int (_fonts.size ())) { + if (s < int(_fonts.size())) { return _fonts[s]; } - return optional (); + return {}; } + void SystemFontDialog::setup_sensitivity () { - wxButton* ok = dynamic_cast (FindWindowById (wxID_OK, this)); + auto ok = dynamic_cast (FindWindowById(wxID_OK, this)); if (ok) { ok->Enable (_list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1); } diff --git a/src/wx/system_font_dialog.h b/src/wx/system_font_dialog.h index da51c9c3a..59639d2b0 100644 --- a/src/wx/system_font_dialog.h +++ b/src/wx/system_font_dialog.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + /** @class SystemFontDialog * @brief A dialog box to select one of the "system" fonts on Windows. * @@ -26,6 +27,7 @@ * one of those fonts. */ + #include "lib/warnings.h" DCPOMATIC_DISABLE_WARNINGS #include @@ -34,8 +36,10 @@ DCPOMATIC_ENABLE_WARNINGS #include #include + class wxListCtrl; + class SystemFontDialog : public wxDialog { public: diff --git a/test/audio_mapping_test.cc b/test/audio_mapping_test.cc index 0acc922b6..1e56df387 100644 --- a/test/audio_mapping_test.cc +++ b/test/audio_mapping_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,19 +18,23 @@ */ + /** @file test/audio_mapping_test.cc * @brief Test AudioMapping class. * @ingroup selfcontained */ + #include #include "lib/audio_mapping.h" #include "lib/util.h" + using std::list; using std::string; using boost::optional; + BOOST_AUTO_TEST_CASE (audio_mapping_test) { AudioMapping none; @@ -43,11 +47,11 @@ BOOST_AUTO_TEST_CASE (audio_mapping_test) for (int i = 0; i < 4; ++i) { for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) { - BOOST_CHECK_EQUAL (four.get (i, j), (i == 0 && j == 1) ? 1 : 0); + BOOST_CHECK_EQUAL (four.get(i, j), (i == 0 && j == 1) ? 1 : 0); } } - list mapped = four.mapped_output_channels (); + auto mapped = four.mapped_output_channels (); BOOST_CHECK_EQUAL (mapped.size(), 1U); BOOST_CHECK_EQUAL (mapped.front(), 1); @@ -60,17 +64,19 @@ BOOST_AUTO_TEST_CASE (audio_mapping_test) } } + static void -guess_check (string filename, int output_channel) +guess_check (boost::filesystem::path filename, int output_channel) { AudioMapping m (1, 8); - m.make_default (0, optional(filename)); + m.make_default (0, filename); for (int i = 0; i < 8; ++i) { BOOST_TEST_INFO (filename); BOOST_CHECK_CLOSE (m.get(0, i), i == output_channel ? 1 : 0, 0.01); } } + BOOST_AUTO_TEST_CASE (audio_mapping_guess_test) { guess_check ("stuff_L_nonsense.wav", 0); diff --git a/test/cinema_sound_processor_test.cc b/test/cinema_sound_processor_test.cc index b17fd19f9..b53917641 100644 --- a/test/cinema_sound_processor_test.cc +++ b/test/cinema_sound_processor_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2019 Carl Hetherington + Copyright (C) 2019-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,11 +18,13 @@ */ + +#include "lib/datasat_ap2x.h" #include "lib/dolby_cp750.h" #include "lib/usl.h" -#include "lib/datasat_ap2x.h" #include + BOOST_AUTO_TEST_CASE (dolby_cp750_test) { DolbyCP750 ap; @@ -43,6 +45,7 @@ BOOST_AUTO_TEST_CASE (dolby_cp750_test) BOOST_CHECK_CLOSE (ap.db_for_fader_change(6, 3), -(20 + 6.66666666666666666), 0.1); } + BOOST_AUTO_TEST_CASE (usl_test) { USL ap; @@ -63,6 +66,7 @@ BOOST_AUTO_TEST_CASE (usl_test) BOOST_CHECK_CLOSE (ap.db_for_fader_change(6, 3), -(2.5 * 10 + 0.5 * 3.333333333333333333), 0.1); } + BOOST_AUTO_TEST_CASE (datasat_ap2x_test) { DatasatAP2x ap; diff --git a/test/colour_conversion_test.cc b/test/colour_conversion_test.cc index 28545b3f0..c48a0b63a 100644 --- a/test/colour_conversion_test.cc +++ b/test/colour_conversion_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2015 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,11 +18,13 @@ */ + /** @file test/colour_conversion_test.cc * @brief Test ColourConversion class. * @ingroup selfcontained */ + #include "lib/colour_conversion.h" #include "lib/film.h" #include @@ -30,23 +32,27 @@ #include #include + using std::cout; +using std::make_shared; using std::shared_ptr; + BOOST_AUTO_TEST_CASE (colour_conversion_test1) { - ColourConversion A (dcp::ColourConversion::srgb_to_xyz ()); - ColourConversion B (dcp::ColourConversion::rec709_to_xyz ()); + ColourConversion A (dcp::ColourConversion::srgb_to_xyz()); + ColourConversion B (dcp::ColourConversion::rec709_to_xyz()); BOOST_CHECK_EQUAL (A.identifier(), "9840c601d2775bf1b3847254bbaa36a9"); BOOST_CHECK_EQUAL (B.identifier(), "58151ac92fdf333663a62c9a8ba5c5f4"); } + BOOST_AUTO_TEST_CASE (colour_conversion_test2) { ColourConversion A (dcp::ColourConversion::srgb_to_xyz ()); xmlpp::Document doc; - xmlpp::Element* root = doc.create_root_node ("Test"); + auto root = doc.create_root_node ("Test"); A.as_xml (root); BOOST_CHECK_EQUAL ( doc.write_to_string_formatted ("UTF-8"), @@ -73,11 +79,12 @@ BOOST_AUTO_TEST_CASE (colour_conversion_test2) ); } + BOOST_AUTO_TEST_CASE (colour_conversion_test3) { - ColourConversion A (dcp::ColourConversion::rec709_to_xyz ()); + ColourConversion A (dcp::ColourConversion::rec709_to_xyz()); xmlpp::Document doc; - xmlpp::Element* root = doc.create_root_node ("Test"); + auto root = doc.create_root_node ("Test"); A.as_xml (root); BOOST_CHECK_EQUAL ( doc.write_to_string_formatted ("UTF-8"), @@ -101,15 +108,16 @@ BOOST_AUTO_TEST_CASE (colour_conversion_test3) ); } + /** Test a round trip via the XML representation */ BOOST_AUTO_TEST_CASE (colour_conversion_test4) { - for (auto const& i: PresetColourConversion::all ()) { + for (auto const& i: PresetColourConversion::all()) { xmlpp::Document out; - xmlpp::Element* out_root = out.create_root_node ("Test"); + auto out_root = out.create_root_node("Test"); i.conversion.as_xml (out_root); - shared_ptr in (new cxml::Document ("Test")); - in->read_string (out.write_to_string ("UTF-8")); - BOOST_CHECK (ColourConversion::from_xml (in, Film::current_state_version).get () == i.conversion); + auto in = make_shared ("Test"); + in->read_string (out.write_to_string("UTF-8")); + BOOST_CHECK (ColourConversion::from_xml(in, Film::current_state_version).get() == i.conversion); } } diff --git a/test/dcp_playback_test.cc b/test/dcp_playback_test.cc index 1e587e93e..ef1b623e7 100644 --- a/test/dcp_playback_test.cc +++ b/test/dcp_playback_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington + Copyright (C) 2018-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,13 +18,16 @@ */ -#include "lib/film.h" + #include "lib/butler.h" -#include "lib/player.h" #include "lib/dcp_content.h" +#include "lib/film.h" +#include "lib/player.h" #include "test.h" #include + +using std::make_shared; using std::pair; using std::shared_ptr; using boost::optional; @@ -33,28 +36,29 @@ using namespace boost::placeholders; #endif using namespace dcpomatic; + /** Simulate the work that the player does, for profiling */ BOOST_AUTO_TEST_CASE (dcp_playback_test) { - shared_ptr film = new_test_film ("dcp_playback_test"); - shared_ptr content (new DCPContent(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV")); + auto film = new_test_film ("dcp_playback_test"); + auto content = make_shared(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV"); film->examine_and_add_content (content); BOOST_REQUIRE (!wait_for_jobs()); - shared_ptr butler ( - new Butler( - film, - shared_ptr(new Player(film)), - AudioMapping(6, 6), - 6, - bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), - VideoRange::FULL, - false, - true) + auto butler = std::make_shared( + film, + shared_ptr(new Player(film)), + AudioMapping(6, 6), + 6, + bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), + VideoRange::FULL, + false, + true ); - float* audio_buffer = new float[2000*6]; + + auto audio_buffer = new float[2000 * 6]; while (true) { - pair, DCPTime> p = butler->get_video (true, 0); + auto p = butler->get_video (true, 0); if (!p.first) { break; } diff --git a/test/file_group_test.cc b/test/file_group_test.cc index 1d42741b6..f974a3725 100644 --- a/test/file_group_test.cc +++ b/test/file_group_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2014 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,19 +18,23 @@ */ + /** @file test/file_group_test.cc * @brief Test FileGroup class. * @ingroup selfcontained */ -#include -#include + +#include "lib/file_group.h" #include #include -#include "lib/file_group.h" +#include +#include + using std::vector; + BOOST_AUTO_TEST_CASE (file_group_test) { /* Random data; must be big enough for all the files */ @@ -53,16 +57,17 @@ BOOST_AUTO_TEST_CASE (file_group_test) total_length += length[i]; } - vector name; boost::filesystem::create_directories ("build/test/file_group_test"); - name.push_back ("build/test/file_group_test/A"); - name.push_back ("build/test/file_group_test/B"); - name.push_back ("build/test/file_group_test/C"); - name.push_back ("build/test/file_group_test/D"); + vector name = { + "build/test/file_group_test/A", + "build/test/file_group_test/B", + "build/test/file_group_test/C", + "build/test/file_group_test/D" + }; int base = 0; for (int i = 0; i < num_files; ++i) { - FILE* f = fopen (name[i].string().c_str(), "wb"); + auto f = fopen (name[i].string().c_str(), "wb"); fwrite (data + base, 1, length[i], f); fclose (f); base += length[i]; @@ -74,51 +79,51 @@ BOOST_AUTO_TEST_CASE (file_group_test) int pos = 0; /* Basic read from 0 */ - BOOST_CHECK_EQUAL (fg.read (test, 64), 64); - BOOST_CHECK_EQUAL (memcmp (data, test, 64), 0); + BOOST_CHECK_EQUAL (fg.read(test, 64), 64); + BOOST_CHECK_EQUAL (memcmp(data, test, 64), 0); pos += 64; /* Another read following the previous */ - BOOST_CHECK_EQUAL (fg.read (test, 4), 4); - BOOST_CHECK_EQUAL (memcmp (data + pos, test, 4), 0); + BOOST_CHECK_EQUAL (fg.read(test, 4), 4); + BOOST_CHECK_EQUAL (memcmp(data + pos, test, 4), 0); pos += 4; /* Read overlapping A and B */ - BOOST_CHECK_EQUAL (fg.read (test, 128), 128); - BOOST_CHECK_EQUAL (memcmp (data + pos, test, 128), 0); + BOOST_CHECK_EQUAL (fg.read(test, 128), 128); + BOOST_CHECK_EQUAL (memcmp(data + pos, test, 128), 0); pos += 128; /* Read overlapping B/C/D and over-reading by a lot */ - BOOST_CHECK_EQUAL (fg.read (test, total_length * 3), total_length - pos); - BOOST_CHECK_EQUAL (memcmp (data + pos, test, total_length - pos), 0); + BOOST_CHECK_EQUAL (fg.read(test, total_length * 3), total_length - pos); + BOOST_CHECK_EQUAL (memcmp(data + pos, test, total_length - pos), 0); /* Over-read by a little */ - BOOST_CHECK_EQUAL (fg.seek (0, SEEK_SET), 0); - BOOST_CHECK_EQUAL (fg.read (test, total_length), total_length); - BOOST_CHECK_EQUAL (fg.read (test, 1), 0); + BOOST_CHECK_EQUAL (fg.seek(0, SEEK_SET), 0); + BOOST_CHECK_EQUAL (fg.read(test, total_length), total_length); + BOOST_CHECK_EQUAL (fg.read(test, 1), 0); /* Seeking off the end of the file should not give an error */ - BOOST_CHECK_EQUAL (fg.seek (total_length * 2, SEEK_SET), total_length * 2); + BOOST_CHECK_EQUAL (fg.seek(total_length * 2, SEEK_SET), total_length * 2); /* and attempting to read should return nothing */ - BOOST_CHECK_EQUAL (fg.read (test, 64), 0); + BOOST_CHECK_EQUAL (fg.read(test, 64), 0); /* but the requested seek should be remembered, so if we now go back (relatively) */ - BOOST_CHECK_EQUAL (fg.seek (-total_length * 2, SEEK_CUR), 0); + BOOST_CHECK_EQUAL (fg.seek(-total_length * 2, SEEK_CUR), 0); /* we should be at the start again */ - BOOST_CHECK_EQUAL (fg.read (test, 64), 64); - BOOST_CHECK_EQUAL (memcmp (data, test, 64), 0); + BOOST_CHECK_EQUAL (fg.read(test, 64), 64); + BOOST_CHECK_EQUAL (memcmp(data, test, 64), 0); /* SEEK_SET */ - BOOST_CHECK_EQUAL (fg.seek (999, SEEK_SET), 999); - BOOST_CHECK_EQUAL (fg.read (test, 64), 64); - BOOST_CHECK_EQUAL (memcmp (data + 999, test, 64), 0); + BOOST_CHECK_EQUAL (fg.seek(999, SEEK_SET), 999); + BOOST_CHECK_EQUAL (fg.read(test, 64), 64); + BOOST_CHECK_EQUAL (memcmp(data + 999, test, 64), 0); /* SEEK_CUR */ - BOOST_CHECK_EQUAL (fg.seek (42, SEEK_CUR), 999 + 64 + 42); - BOOST_CHECK_EQUAL (fg.read (test, 64), 64); - BOOST_CHECK_EQUAL (memcmp (data + 999 + 64 + 42, test, 64), 0); + BOOST_CHECK_EQUAL (fg.seek(42, SEEK_CUR), 999 + 64 + 42); + BOOST_CHECK_EQUAL (fg.read(test, 64), 64); + BOOST_CHECK_EQUAL (memcmp(data + 999 + 64 + 42, test, 64), 0); /* SEEK_END */ - BOOST_CHECK_EQUAL (fg.seek (1077, SEEK_END), total_length - 1077); - BOOST_CHECK_EQUAL (fg.read (test, 256), 256); - BOOST_CHECK_EQUAL (memcmp (data + total_length - 1077, test, 256), 0); + BOOST_CHECK_EQUAL (fg.seek(1077, SEEK_END), total_length - 1077); + BOOST_CHECK_EQUAL (fg.read(test, 256), 256); + BOOST_CHECK_EQUAL (memcmp(data + total_length - 1077, test, 256), 0); } diff --git a/test/file_log_test.cc b/test/file_log_test.cc index e0eeba010..dca1d4386 100644 --- a/test/file_log_test.cc +++ b/test/file_log_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,20 +18,20 @@ */ + /** @file test/file_log_test.cc * @brief Test FileLog. * @ingroup selfcontained */ + #include "lib/file_log.h" #include -#include -using std::cout; BOOST_AUTO_TEST_CASE (file_log_test) { FileLog log ("test/data/short.log"); - BOOST_CHECK_EQUAL (log.head_and_tail (1024), "This is a short log.\nWith only two lines.\n"); - BOOST_CHECK_EQUAL (log.head_and_tail (8), "This is \n .\n .\n .\no lines.\n"); + BOOST_CHECK_EQUAL (log.head_and_tail(1024), "This is a short log.\nWith only two lines.\n"); + BOOST_CHECK_EQUAL (log.head_and_tail(8), "This is \n .\n .\n .\no lines.\n"); } diff --git a/test/image_filename_sorter_test.cc b/test/image_filename_sorter_test.cc index 7512fdffb..eb662a120 100644 --- a/test/image_filename_sorter_test.cc +++ b/test/image_filename_sorter_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015-2017 Carl Hetherington + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,45 +18,50 @@ */ + /** @file test/image_filename_sorter_test.cc * @brief Test ImageFilenameSorter * @ingroup selfcontained */ + #include "lib/image_filename_sorter.h" #include "lib/compose.hpp" #include + using std::random_shuffle; using std::sort; using std::vector; + BOOST_AUTO_TEST_CASE (image_filename_sorter_test1) { ImageFilenameSorter x; - BOOST_CHECK (x ("abc0000000001", "abc0000000002")); - BOOST_CHECK (x ("1", "2")); - BOOST_CHECK (x ("1", "0002")); - BOOST_CHECK (x ("0001", "2")); - BOOST_CHECK (x ("1", "999")); - BOOST_CHECK (x ("00057.tif", "00166.tif")); - BOOST_CHECK (x ("/my/numeric999/path/00057.tif", "/my/numeric999/path/00166.tif")); - BOOST_CHECK (x ("1_01.tif", "1_02.tif")); - BOOST_CHECK (x ("EWS_DCP_092815_000000.j2c", "EWS_DCP_092815_000001.j2c")); - BOOST_CHECK (x ("ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86352.dpx", "ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86353.dpx")); - - BOOST_CHECK (!x ("abc0000000002", "abc0000000001")); - BOOST_CHECK (!x ("2", "1")); - BOOST_CHECK (!x ("0002", "1")); - BOOST_CHECK (!x ("2", "0001")); - BOOST_CHECK (!x ("999", "1")); - BOOST_CHECK (!x ("/my/numeric999/path/00166.tif", "/my/numeric999/path/00057.tif")); - BOOST_CHECK (!x ("1_02.tif", "1_01.tif")); - BOOST_CHECK (!x ("EWS_DCP_092815_000000.j2c", "EWS_DCP_092815_000000.j2c")); - BOOST_CHECK (!x ("EWS_DCP_092815_000100.j2c", "EWS_DCP_092815_000000.j2c")); - BOOST_CHECK (!x ("ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86353.dpx", "ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86352.dpx")); + BOOST_CHECK (x("abc0000000001", "abc0000000002")); + BOOST_CHECK (x("1", "2")); + BOOST_CHECK (x("1", "0002")); + BOOST_CHECK (x("0001", "2")); + BOOST_CHECK (x("1", "999")); + BOOST_CHECK (x("00057.tif", "00166.tif")); + BOOST_CHECK (x("/my/numeric999/path/00057.tif", "/my/numeric999/path/00166.tif")); + BOOST_CHECK (x("1_01.tif", "1_02.tif")); + BOOST_CHECK (x("EWS_DCP_092815_000000.j2c", "EWS_DCP_092815_000001.j2c")); + BOOST_CHECK (x("ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86352.dpx", "ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86353.dpx")); + + BOOST_CHECK (!x("abc0000000002", "abc0000000001")); + BOOST_CHECK (!x("2", "1")); + BOOST_CHECK (!x("0002", "1")); + BOOST_CHECK (!x("2", "0001")); + BOOST_CHECK (!x("999", "1")); + BOOST_CHECK (!x("/my/numeric999/path/00166.tif", "/my/numeric999/path/00057.tif")); + BOOST_CHECK (!x("1_02.tif", "1_01.tif")); + BOOST_CHECK (!x("EWS_DCP_092815_000000.j2c", "EWS_DCP_092815_000000.j2c")); + BOOST_CHECK (!x("EWS_DCP_092815_000100.j2c", "EWS_DCP_092815_000000.j2c")); + BOOST_CHECK (!x("ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86353.dpx", "ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86352.dpx")); } + /** Test a sort of a lot of paths. Mostly useful for profiling. */ BOOST_AUTO_TEST_CASE (image_filename_sorter_test2) { diff --git a/test/image_proxy_test.cc b/test/image_proxy_test.cc index 750b77561..a9872b958 100644 --- a/test/image_proxy_test.cc +++ b/test/image_proxy_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -25,6 +25,7 @@ #include +using std::make_shared; using std::shared_ptr; @@ -37,14 +38,14 @@ BOOST_AUTO_TEST_CASE (j2k_image_proxy_same_test) /* The files don't matter here, we just need some data to compare */ { - shared_ptr proxy1(new J2KImageProxy(data_file0, dcp::Size(1998, 1080), AV_PIX_FMT_RGB48)); - shared_ptr proxy2(new J2KImageProxy(data_file0, dcp::Size(1998, 1080), AV_PIX_FMT_RGB48)); + auto proxy1 = make_shared(data_file0, dcp::Size(1998, 1080), AV_PIX_FMT_RGB48); + auto proxy2 = make_shared(data_file0, dcp::Size(1998, 1080), AV_PIX_FMT_RGB48); BOOST_CHECK (proxy1->same(proxy2)); } { - shared_ptr proxy1(new J2KImageProxy(data_file0, dcp::Size(1998, 1080), AV_PIX_FMT_RGB48)); - shared_ptr proxy2(new J2KImageProxy(data_file1, dcp::Size(1998, 1080), AV_PIX_FMT_RGB48)); + auto proxy1 = make_shared(data_file0, dcp::Size(1998, 1080), AV_PIX_FMT_RGB48); + auto proxy2 = make_shared(data_file1, dcp::Size(1998, 1080), AV_PIX_FMT_RGB48); BOOST_CHECK (!proxy1->same(proxy2)); } } @@ -53,14 +54,14 @@ BOOST_AUTO_TEST_CASE (j2k_image_proxy_same_test) BOOST_AUTO_TEST_CASE (ffmpeg_image_proxy_same_test) { { - shared_ptr proxy1(new FFmpegImageProxy(data_file0, VideoRange::FULL)); - shared_ptr proxy2(new FFmpegImageProxy(data_file0, VideoRange::FULL)); + auto proxy1 = make_shared(data_file0, VideoRange::FULL); + auto proxy2 = make_shared(data_file0, VideoRange::FULL); BOOST_CHECK (proxy1->same(proxy2)); } { - shared_ptr proxy1(new FFmpegImageProxy(data_file0, VideoRange::FULL)); - shared_ptr proxy2(new FFmpegImageProxy(data_file1, VideoRange::FULL)); + auto proxy1 = make_shared(data_file0, VideoRange::FULL); + auto proxy2 = make_shared(data_file1, VideoRange::FULL); BOOST_CHECK (!proxy1->same(proxy2)); } } diff --git a/test/interrupt_encoder_test.cc b/test/interrupt_encoder_test.cc index e146d2916..bc90dab42 100644 --- a/test/interrupt_encoder_test.cc +++ b/test/interrupt_encoder_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,34 +18,39 @@ */ + /** @file test/interrupt_encoder_test.cc * @brief Test clean shutdown of threads if a DCP encode is interrupted. * @ingroup feature */ -#include "lib/film.h" + +#include "lib/audio_content.h" +#include "lib/cross.h" #include "lib/dcp_content_type.h" -#include "lib/ratio.h" #include "lib/ffmpeg_content.h" -#include "lib/audio_content.h" +#include "lib/film.h" #include "lib/job_manager.h" -#include "lib/cross.h" +#include "lib/ratio.h" #include "test.h" #include + +using std::make_shared; using std::shared_ptr; + /** Interrupt a DCP encode when it is in progress, as this used to (still does?) * sometimes give an error related to pthreads. */ BOOST_AUTO_TEST_CASE (interrupt_encoder_test) { - shared_ptr film = new_test_film ("interrupt_encoder_test"); - film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR")); - film->set_container (Ratio::from_id ("185")); + auto film = new_test_film ("interrupt_encoder_test"); + film->set_dcp_content_type (DCPContentType::from_isdcf_name("FTR")); + film->set_container (Ratio::from_id("185")); film->set_name ("interrupt_encoder_test"); - shared_ptr content (new FFmpegContent(TestPaths::private_data() / "prophet_long_clip.mkv")); + auto content = make_shared(TestPaths::private_data() / "prophet_long_clip.mkv"); film->examine_and_add_content (content); BOOST_REQUIRE (!wait_for_jobs()); diff --git a/test/kdm_naming_test.cc b/test/kdm_naming_test.cc index c58de3471..f692c165d 100644 --- a/test/kdm_naming_test.cc +++ b/test/kdm_naming_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,22 +18,25 @@ */ + #include "lib/cinema.h" -#include "lib/screen.h" #include "lib/config.h" #include "lib/content_factory.h" #include "lib/film.h" #include "lib/kdm_with_metadata.h" +#include "lib/screen.h" #include "test.h" #include +using std::dynamic_pointer_cast; using std::list; +using std::make_shared; +using std::shared_ptr; using std::string; using std::vector; -using std::shared_ptr; using boost::optional; -using std::dynamic_pointer_cast; + static bool @@ -42,39 +45,41 @@ confirm_overwrite (boost::filesystem::path) return true; } + static shared_ptr cinema_a_screen_1; static shared_ptr cinema_a_screen_2; static shared_ptr cinema_b_screen_x; static shared_ptr cinema_b_screen_y; static shared_ptr cinema_b_screen_z; + BOOST_AUTO_TEST_CASE (single_kdm_naming_test) { - Config* c = Config::instance(); + auto c = Config::instance(); - dcp::Certificate cert = c->decryption_chain()->leaf(); + auto cert = c->decryption_chain()->leaf(); /* Cinema A: UTC +4:30 */ - shared_ptr cinema_a (new Cinema("Cinema A", list(), "", 4, 30)); - cinema_a_screen_1.reset(new dcpomatic::Screen("Screen 1", "", cert, vector())); + auto cinema_a = make_shared("Cinema A", list(), "", 4, 30); + cinema_a_screen_1 = make_shared("Screen 1", "", cert, vector()); cinema_a->add_screen (cinema_a_screen_1); - cinema_a_screen_2.reset(new dcpomatic::Screen("Screen 2", "", cert, vector())); + cinema_a_screen_2 = make_shared("Screen 2", "", cert, vector()); cinema_a->add_screen (cinema_a_screen_2); c->add_cinema (cinema_a); /* Cinema B: UTC -1:00 */ - shared_ptr cinema_b (new Cinema("Cinema B", list(), "", -1, 0)); - cinema_b_screen_x.reset(new dcpomatic::Screen("Screen X", "", cert, vector())); + auto cinema_b = make_shared("Cinema B", list(), "", -1, 0); + cinema_b_screen_x = make_shared("Screen X", "", cert, vector()); cinema_b->add_screen (cinema_b_screen_x); - cinema_b_screen_y.reset(new dcpomatic::Screen("Screen Y", "", cert, vector())); + cinema_b_screen_y = make_shared("Screen Y", "", cert, vector()); cinema_b->add_screen (cinema_b_screen_y); - cinema_b_screen_z.reset(new dcpomatic::Screen("Screen Z", "", cert, vector())); + cinema_b_screen_z = make_shared("Screen Z", "", cert, vector()); cinema_b->add_screen (cinema_b_screen_z); c->add_cinema (cinema_a); /* Film */ boost::filesystem::remove_all ("build/test/single_kdm_naming_test"); - shared_ptr film = new_test_film2 ("single_kdm_naming_test"); + auto film = new_test_film2 ("single_kdm_naming_test"); film->set_name ("my_great_film"); film->examine_and_add_content (content_factory("test/data/flat_black.png").front()); BOOST_REQUIRE (!wait_for_jobs()); @@ -88,8 +93,8 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test) dcp::LocalTime until (cert.not_after()); until.add_months (-2); - string const from_string = from.date() + " " + from.time_of_day(true, false); - string const until_string = until.date() + " " + until.time_of_day(true, false); + auto const from_string = from.date() + " " + from.time_of_day(true, false); + auto const until_string = until.date() + " " + until.time_of_day(true, false); auto cpl = cpls.front().cpl_file; auto kdm = kdm_for_screen ( @@ -110,12 +115,12 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test) &confirm_overwrite ); - string from_time = from.time_of_day (true, false); + auto from_time = from.time_of_day (true, false); boost::algorithm::replace_all (from_time, ":", "-"); - string until_time = until.time_of_day (true, false); + auto until_time = until.time_of_day (true, false); boost::algorithm::replace_all (until_time, ":", "-"); - string const ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time); + auto const ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time); BOOST_CHECK_MESSAGE (boost::filesystem::exists("build/test/single_kdm_naming_test/" + ref), "File " << ref << " not found"); } @@ -124,7 +129,7 @@ BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on( { using boost::filesystem::path; - dcp::Certificate cert = Config::instance()->decryption_chain()->leaf(); + auto cert = Config::instance()->decryption_chain()->leaf(); /* Film */ boost::filesystem::remove_all ("build/test/directory_kdm_naming_test"); diff --git a/test/no_use_video_test.cc b/test/no_use_video_test.cc index 3c21675c7..2cc914f84 100644 --- a/test/no_use_video_test.cc +++ b/test/no_use_video_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. diff --git a/test/reel_writer_test.cc b/test/reel_writer_test.cc index 6fa571500..18a327563 100644 --- a/test/reel_writer_test.cc +++ b/test/reel_writer_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2019 Carl Hetherington + Copyright (C) 2019-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,17 +18,19 @@ */ + /** @file test/reel_writer_test.cc * @brief Test ReelWriter class. * @ingroup selfcontained */ -#include "lib/reel_writer.h" -#include "lib/film.h" -#include "lib/cross.h" -#include "lib/content_factory.h" -#include "lib/content.h" + #include "lib/audio_content.h" +#include "lib/content.h" +#include "lib/content_factory.h" +#include "lib/cross.h" +#include "lib/film.h" +#include "lib/reel_writer.h" #include "lib/video_content.h" #include "test.h" #include @@ -38,16 +40,19 @@ #include #include -using std::string; + using std::shared_ptr; +using std::string; using boost::optional; + static bool equal (dcp::FrameInfo a, ReelWriter const & writer, shared_ptr file, Frame frame, Eyes eyes) { - dcp::FrameInfo b = writer.read_frame_info(file, frame, eyes); + auto b = writer.read_frame_info(file, frame, eyes); return a.offset == b.offset && a.size == b.size && a.hash == b.hash; } + BOOST_AUTO_TEST_CASE (write_frame_info_test) { auto film = new_test_film2 ("write_frame_info_test"); @@ -97,30 +102,27 @@ BOOST_AUTO_TEST_CASE (write_frame_info_test) } } + /** Check that the reel writer correctly re-uses a video asset changed if we remake * a DCP with no video changes. */ BOOST_AUTO_TEST_CASE (reel_reuse_video_test) { /* Make a DCP */ - auto film = new_test_film2 ("reel_reuse_video_test"); auto video = content_factory("test/data/flat_red.png").front(); - film->examine_and_add_content (video); - BOOST_REQUIRE (!wait_for_jobs()); auto audio = content_factory("test/data/white.wav").front(); - film->examine_and_add_content (audio); - BOOST_REQUIRE (!wait_for_jobs()); + auto film = new_test_film2 ("reel_reuse_video_test", { video, audio }); make_and_verify_dcp (film); /* Find main picture and sound asset IDs */ dcp::DCP dcp1 (film->dir(film->dcp_name())); dcp1.read (); BOOST_REQUIRE_EQUAL (dcp1.cpls().size(), 1U); - BOOST_REQUIRE_EQUAL (dcp1.cpls().front()->reels().size(), 1U); - BOOST_REQUIRE (dcp1.cpls().front()->reels().front()->main_picture()); - BOOST_REQUIRE (dcp1.cpls().front()->reels().front()->main_sound()); - string const picture_id = dcp1.cpls().front()->reels().front()->main_picture()->asset()->id(); - string const sound_id = dcp1.cpls().front()->reels().front()->main_sound()->asset()->id(); + BOOST_REQUIRE_EQUAL (dcp1.cpls()[0]->reels().size(), 1U); + BOOST_REQUIRE (dcp1.cpls()[0]->reels()[0]->main_picture()); + BOOST_REQUIRE (dcp1.cpls()[0]->reels()[0]->main_sound()); + auto const picture_id = dcp1.cpls()[0]->reels()[0]->main_picture()->asset()->id(); + auto const sound_id = dcp1.cpls()[0]->reels()[0]->main_sound()->asset()->id(); /* Change the audio and re-make */ audio->audio->set_gain (-3); @@ -130,11 +132,11 @@ BOOST_AUTO_TEST_CASE (reel_reuse_video_test) dcp::DCP dcp2 (film->dir(film->dcp_name())); dcp2.read (); BOOST_REQUIRE_EQUAL (dcp2.cpls().size(), 1U); - BOOST_REQUIRE_EQUAL (dcp2.cpls().front()->reels().size(), 1U); - BOOST_REQUIRE (dcp2.cpls().front()->reels().front()->main_picture()); - BOOST_REQUIRE (dcp2.cpls().front()->reels().front()->main_sound()); - BOOST_CHECK_EQUAL (picture_id, dcp2.cpls().front()->reels().front()->main_picture()->asset()->id()); - BOOST_CHECK (sound_id != dcp2.cpls().front()->reels().front()->main_sound()->asset()->id()); + BOOST_REQUIRE_EQUAL (dcp2.cpls()[0]->reels().size(), 1U); + BOOST_REQUIRE (dcp2.cpls()[0]->reels()[0]->main_picture()); + BOOST_REQUIRE (dcp2.cpls()[0]->reels()[0]->main_sound()); + BOOST_CHECK_EQUAL (picture_id, dcp2.cpls()[0]->reels()[0]->main_picture()->asset()->id()); + BOOST_CHECK (sound_id != dcp2.cpls()[0]->reels().front()->main_sound()->asset()->id()); /* Crop video and re-make */ video->video->set_left_crop (5); @@ -144,9 +146,9 @@ BOOST_AUTO_TEST_CASE (reel_reuse_video_test) dcp::DCP dcp3 (film->dir(film->dcp_name())); dcp3.read (); BOOST_REQUIRE_EQUAL (dcp3.cpls().size(), 1U); - BOOST_REQUIRE_EQUAL (dcp3.cpls().front()->reels().size(), 1U); - BOOST_REQUIRE (dcp3.cpls().front()->reels().front()->main_picture()); - BOOST_REQUIRE (dcp3.cpls().front()->reels().front()->main_sound()); - BOOST_CHECK (picture_id != dcp3.cpls().front()->reels().front()->main_picture()->asset()->id()); - BOOST_CHECK (sound_id != dcp3.cpls().front()->reels().front()->main_sound()->asset()->id()); + BOOST_REQUIRE_EQUAL (dcp3.cpls()[0]->reels().size(), 1U); + BOOST_REQUIRE (dcp3.cpls()[0]->reels()[0]->main_picture()); + BOOST_REQUIRE (dcp3.cpls()[0]->reels()[0]->main_sound()); + BOOST_CHECK (picture_id != dcp3.cpls()[0]->reels()[0]->main_picture()->asset()->id()); + BOOST_CHECK (sound_id != dcp3.cpls()[0]->reels().front()->main_sound()->asset()->id()); } diff --git a/test/resampler_test.cc b/test/resampler_test.cc index 2978d27f9..8009cc9f9 100644 --- a/test/resampler_test.cc +++ b/test/resampler_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2014 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,21 +18,26 @@ */ + /** @file test/resampler_test.cc * @brief Check that the timings that come back from Resampler correspond * to the number of samples it generates. * @ingroup selfcontained */ -#include + #include "lib/audio_buffers.h" #include "lib/resampler.h" +#include #include -using std::pair; + using std::cout; +using std::make_shared; +using std::pair; using std::shared_ptr; + static void resampler_test_one (int from, int to) { @@ -43,12 +48,13 @@ resampler_test_one (int from, int to) /* XXX: no longer checks anything */ for (int64_t i = 0; i < N; i += 1000) { - shared_ptr a (new AudioBuffers (1, 1000)); + auto a = make_shared (1, 1000); a->make_silent (); - pair, Frame> r = resamp.run (a, 0); + auto r = resamp.run (a, 0); } } + BOOST_AUTO_TEST_CASE (resampler_test) { resampler_test_one (44100, 48000); diff --git a/test/socket_test.cc b/test/socket_test.cc index b9aaba9d2..64c154808 100644 --- a/test/socket_test.cc +++ b/test/socket_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,17 +18,19 @@ */ -#include "lib/server.h" + #include "lib/dcpomatic_socket.h" +#include "lib/server.h" #include -#include #include +#include #include #include -using std::string; +using std::make_shared; using std::shared_ptr; +using std::string; using boost::bind; @@ -115,6 +117,7 @@ send (shared_ptr socket, char const* message) socket->write (reinterpret_cast(message), strlen(message) + 1); } + /** Basic test to see if Socket can send and receive data */ BOOST_AUTO_TEST_CASE (socket_basic_test) { @@ -128,7 +131,7 @@ BOOST_AUTO_TEST_CASE (socket_basic_test) tcp::resolver::query query ("127.0.0.1", dcp::raw_convert(TEST_SERVER_PORT)); tcp::resolver::iterator endpoint_iterator = resolver.resolve (query); - shared_ptr socket (new Socket); + auto socket = make_shared(); socket->connect (*endpoint_iterator); send (socket, "Hello world!"); diff --git a/test/subtitle_charset_test.cc b/test/subtitle_charset_test.cc index ada358a63..8233bf023 100644 --- a/test/subtitle_charset_test.cc +++ b/test/subtitle_charset_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington + Copyright (C) 2018-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,34 +18,34 @@ */ -#include "test.h" + #include "lib/content.h" -#include "lib/film.h" #include "lib/content_factory.h" +#include "lib/film.h" #include "lib/string_text_file.h" #include "lib/string_text_file_content.h" +#include "test.h" #include + using std::shared_ptr; using std::dynamic_pointer_cast; + /** Test parsing of UTF16 CR/LF input */ BOOST_AUTO_TEST_CASE (subtitle_charset_test1) { - shared_ptr film = new_test_film2 ("subtitle_charset_test1"); - shared_ptr content = content_factory (TestPaths::private_data() / "PADDINGTON soustitresVFdef.srt").front(); - film->examine_and_add_content (content); - BOOST_REQUIRE (!wait_for_jobs ()); + auto content = content_factory (TestPaths::private_data() / "PADDINGTON soustitresVFdef.srt").front(); + auto film = new_test_film2 ("subtitle_charset_test1", { content }); } + /** Test parsing of OSX input */ BOOST_AUTO_TEST_CASE (subtitle_charset_test2) { - shared_ptr film = new_test_film2 ("subtitle_charset_test2"); - shared_ptr content = content_factory ("test/data/osx.srt").front(); - film->examine_and_add_content (content); - BOOST_REQUIRE (!wait_for_jobs ()); - shared_ptr ts = dynamic_pointer_cast (content); + auto content = content_factory ("test/data/osx.srt").front(); + auto film = new_test_film2 ("subtitle_charset_test2", { content }); + auto ts = dynamic_pointer_cast (content); BOOST_REQUIRE (ts); /* Make sure we got the subtitle data from the file */ BOOST_REQUIRE_EQUAL (content->full_length(film).get(), 6052032); diff --git a/test/subtitle_language_test.cc b/test/subtitle_language_test.cc index af5dee001..e198b78f9 100644 --- a/test/subtitle_language_test.cc +++ b/test/subtitle_language_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. diff --git a/test/upmixer_a_test.cc b/test/upmixer_a_test.cc index 35224ff23..0dc496275 100644 --- a/test/upmixer_a_test.cc +++ b/test/upmixer_a_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,28 +18,33 @@ */ + /** @file test/upmixer_a_test.cc * @brief Check the Upmixer A against some reference sound files. * @ingroup selfcontained */ -#include -#include -#include "lib/film.h" -#include "lib/ratio.h" + +#include "lib/audio_buffers.h" #include "lib/dcp_content_type.h" #include "lib/ffmpeg_content.h" +#include "lib/film.h" #include "lib/player.h" -#include "lib/audio_buffers.h" +#include "lib/ratio.h" #include "lib/upmixer_a.h" #include "test.h" +#include +#include + +using std::make_shared; using std::shared_ptr; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif using namespace dcpomatic; + static SNDFILE* L; static SNDFILE* R; static SNDFILE* C; @@ -47,6 +52,7 @@ static SNDFILE* Lfe; static SNDFILE* Ls; static SNDFILE* Rs; + static void write (shared_ptr b, DCPTime) { @@ -59,14 +65,15 @@ write (shared_ptr b, DCPTime) } + BOOST_AUTO_TEST_CASE (upmixer_a_test) { - shared_ptr film = new_test_film ("upmixer_a_test"); - film->set_container (Ratio::from_id ("185")); - film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR")); + auto film = new_test_film ("upmixer_a_test"); + film->set_container (Ratio::from_id("185")); + film->set_dcp_content_type (DCPContentType::from_isdcf_name("TLR")); film->set_name ("frobozz"); - film->set_audio_processor (AudioProcessor::from_id ("stereo-5.1-upmix-a")); - shared_ptr content (new FFmpegContent ("test/data/white.wav")); + film->set_audio_processor (AudioProcessor::from_id("stereo-5.1-upmix-a")); + auto content = make_shared("test/data/white.wav"); film->examine_and_add_content (content); BOOST_REQUIRE (!wait_for_jobs()); @@ -82,7 +89,7 @@ BOOST_AUTO_TEST_CASE (upmixer_a_test) Ls = sf_open ("build/test/upmixer_a_test/Ls.wav", SFM_WRITE, &info); Rs = sf_open ("build/test/upmixer_a_test/Rs.wav", SFM_WRITE, &info); - shared_ptr player (new Player(film)); + auto player = make_shared(film); player->Audio.connect (bind (&write, _1, _2)); while (!player->pass()) {} -- 2.30.2