summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-04-08 21:32:44 +0200
committerCarl Hetherington <cth@carlh.net>2021-04-08 21:32:44 +0200
commit3339d3bce70afe9ae2ca10e9fcfc4b54b748fbf4 (patch)
tree9cac355432ba25cc3d43017382d73e0640f50996 /src/lib
parent00762c2d9a4240d016150cd7555aee3dad8542ae (diff)
Assorted C++11/formatting cleanups.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_analysis.cc62
-rw-r--r--src/lib/audio_analysis.h14
-rw-r--r--src/lib/audio_decoder.cc11
-rw-r--r--src/lib/audio_decoder.h8
-rw-r--r--src/lib/cross_windows.cc88
-rw-r--r--src/lib/dcp.cc17
-rw-r--r--src/lib/dcp.h15
-rw-r--r--src/lib/dcpomatic_time.h44
-rw-r--r--src/lib/dcpomatic_time_coalesce.h10
-rw-r--r--src/lib/ffmpeg_examiner.cc48
-rw-r--r--src/lib/ffmpeg_examiner.h16
-rw-r--r--src/lib/j2k_encoder.cc18
-rw-r--r--src/lib/j2k_encoder.h11
-rw-r--r--src/lib/json_server.cc35
-rw-r--r--src/lib/kdm_with_metadata.cc45
-rw-r--r--src/lib/kdm_with_metadata.h14
-rw-r--r--src/lib/player_text.h2
-rw-r--r--src/lib/rect.h12
-rw-r--r--src/lib/render_text.cc106
-rw-r--r--src/lib/send_kdm_email_job.cc12
-rw-r--r--src/lib/send_kdm_email_job.h10
-rw-r--r--src/lib/subtitle_analysis.cc13
-rw-r--r--src/lib/subtitle_analysis.h10
-rw-r--r--src/lib/timer.cc33
-rw-r--r--src/lib/timer.h6
-rw-r--r--src/lib/video_content.h3
-rw-r--r--src/lib/zipper.cc6
-rw-r--r--src/lib/zipper.h6
28 files changed, 426 insertions, 249 deletions
diff --git a/src/lib/audio_analysis.cc b/src/lib/audio_analysis.cc
index 22c14c764..b16fa708a 100644
--- a/src/lib/audio_analysis.cc
+++ b/src/lib/audio_analysis.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "audio_analysis.h"
#include "cross.h"
#include "util.h"
@@ -35,28 +36,33 @@ DCPOMATIC_ENABLE_WARNINGS
#include <iostream>
#include <inttypes.h>
-using std::ostream;
-using std::istream;
-using std::string;
-using std::vector;
+
using std::cout;
+using std::dynamic_pointer_cast;
+using std::istream;
+using std::list;
+using std::make_pair;
+using std::make_shared;
using std::max;
+using std::ostream;
using std::pair;
-using std::make_pair;
-using std::list;
using std::shared_ptr;
+using std::string;
+using std::vector;
using boost::optional;
-using std::dynamic_pointer_cast;
using dcp::raw_convert;
using namespace dcpomatic;
+
int const AudioAnalysis::_current_state_version = 3;
+
AudioAnalysis::AudioAnalysis (int channels)
{
_data.resize (channels);
}
+
AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
{
cxml::Document f ("AudioAnalysis");
@@ -79,26 +85,27 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
for (auto i: f.node_children ("SamplePeak")) {
_sample_peak.push_back (
- PeakTime (
+ PeakTime(
dcp::raw_convert<float>(i->content()), DCPTime(i->number_attribute<Frame>("Time"))
)
);
}
- for (auto i: f.node_children ("TruePeak")) {
- _true_peak.push_back (dcp::raw_convert<float> (i->content ()));
+ for (auto i: f.node_children("TruePeak")) {
+ _true_peak.push_back (dcp::raw_convert<float>(i->content()));
}
- _integrated_loudness = f.optional_number_child<float> ("IntegratedLoudness");
- _loudness_range = f.optional_number_child<float> ("LoudnessRange");
+ _integrated_loudness = f.optional_number_child<float>("IntegratedLoudness");
+ _loudness_range = f.optional_number_child<float>("LoudnessRange");
- _analysis_gain = f.optional_number_child<double> ("AnalysisGain");
- _samples_per_point = f.number_child<int64_t> ("SamplesPerPoint");
- _sample_rate = f.number_child<int64_t> ("SampleRate");
+ _analysis_gain = f.optional_number_child<double>("AnalysisGain");
+ _samples_per_point = f.number_child<int64_t>("SamplesPerPoint");
+ _sample_rate = f.number_child<int64_t>("SampleRate");
_leqm = f.optional_number_child<double>("Leqm");
}
+
void
AudioAnalysis::add_point (int c, AudioPoint const & p)
{
@@ -106,43 +113,47 @@ AudioAnalysis::add_point (int c, AudioPoint const & p)
_data[c].push_back (p);
}
+
AudioPoint
AudioAnalysis::get_point (int c, int p) const
{
- DCPOMATIC_ASSERT (p < points (c));
+ DCPOMATIC_ASSERT (p < points(c));
return _data[c][p];
}
+
int
AudioAnalysis::channels () const
{
return _data.size ();
}
+
int
AudioAnalysis::points (int c) const
{
- DCPOMATIC_ASSERT (c < channels ());
+ DCPOMATIC_ASSERT (c < channels());
return _data[c].size ();
}
+
void
AudioAnalysis::write (boost::filesystem::path filename)
{
- shared_ptr<xmlpp::Document> doc (new xmlpp::Document);
+ auto doc = make_shared<xmlpp::Document>();
xmlpp::Element* root = doc->create_root_node ("AudioAnalysis");
- root->add_child("Version")->add_child_text (raw_convert<string> (_current_state_version));
+ root->add_child("Version")->add_child_text(raw_convert<string>(_current_state_version));
for (auto& i: _data) {
- xmlpp::Element* channel = root->add_child ("Channel");
+ auto channel = root->add_child ("Channel");
for (auto& j: i) {
j.as_xml (channel->add_child ("Point"));
}
}
for (size_t i = 0; i < _sample_peak.size(); ++i) {
- xmlpp::Element* n = root->add_child("SamplePeak");
+ auto n = root->add_child("SamplePeak");
n->add_child_text (raw_convert<string> (_sample_peak[i].peak));
n->set_attribute ("Time", raw_convert<string> (_sample_peak[i].time.get()));
}
@@ -173,6 +184,7 @@ AudioAnalysis::write (boost::filesystem::path filename)
doc->write_to_file_formatted (filename.string ());
}
+
float
AudioAnalysis::gain_correction (shared_ptr<const Playlist> playlist)
{
@@ -182,17 +194,18 @@ AudioAnalysis::gain_correction (shared_ptr<const Playlist> playlist)
what correction is now needed to make it look `right'.
*/
DCPOMATIC_ASSERT (playlist->content().front()->audio);
- return playlist->content().front()->audio->gain() - analysis_gain().get ();
+ return playlist->content().front()->audio->gain() - analysis_gain().get();
}
return 0.0f;
}
+
/** @return Peak across all channels, and the channel number it is on */
pair<AudioAnalysis::PeakTime, int>
AudioAnalysis::overall_sample_peak () const
{
- DCPOMATIC_ASSERT (!_sample_peak.empty ());
+ DCPOMATIC_ASSERT (!_sample_peak.empty());
optional<PeakTime> pt;
int c = 0;
@@ -207,6 +220,7 @@ AudioAnalysis::overall_sample_peak () const
return make_pair (pt.get(), c);
}
+
optional<float>
AudioAnalysis::overall_true_peak () const
{
diff --git a/src/lib/audio_analysis.h b/src/lib/audio_analysis.h
index c3aec6e29..263e8a8a0 100644
--- a/src/lib/audio_analysis.h
+++ b/src/lib/audio_analysis.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,9 +18,11 @@
*/
+
#ifndef DCPOMATIC_AUDIO_ANALYSIS_H
#define DCPOMATIC_AUDIO_ANALYSIS_H
+
#include "dcpomatic_time.h"
#include "audio_point.h"
#include <libcxml/cxml.h>
@@ -28,12 +30,15 @@
#include <boost/filesystem.hpp>
#include <vector>
+
namespace xmlpp {
class Element;
}
+
class Playlist;
+
class AudioAnalysis : public boost::noncopyable
{
public:
@@ -129,7 +134,7 @@ public:
float gain_correction (std::shared_ptr<const Playlist> playlist);
private:
- std::vector<std::vector<AudioPoint> > _data;
+ std::vector<std::vector<AudioPoint>> _data;
std::vector<PeakTime> _sample_peak;
std::vector<float> _true_peak;
boost::optional<float> _integrated_loudness;
@@ -140,10 +145,11 @@ private:
* happened.
*/
boost::optional<double> _analysis_gain;
- int64_t _samples_per_point;
- int _sample_rate;
+ int64_t _samples_per_point = 0;
+ int _sample_rate = 0;
static int const _current_state_version;
};
+
#endif
diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc
index f7f147bd9..77c9b0695 100644
--- a/src/lib/audio_decoder.cc
+++ b/src/lib/audio_decoder.cc
@@ -18,6 +18,7 @@
*/
+
#include "audio_decoder.h"
#include "audio_buffers.h"
#include "audio_content.h"
@@ -29,6 +30,7 @@
#include "i18n.h"
+
using std::cout;
using std::map;
using std::pair;
@@ -37,6 +39,7 @@ using std::make_shared;
using boost::optional;
using namespace dcpomatic;
+
AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> content, bool fast)
: DecoderPart (parent)
, _content (content)
@@ -48,6 +51,7 @@ AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> cont
}
}
+
/** @param time_already_delayed true if the delay should not be added to time */
void
AudioDecoder::emit (shared_ptr<const Film> film, AudioStreamPtr stream, shared_ptr<const AudioBuffers> data, ContentTime time, bool time_already_delayed)
@@ -97,7 +101,7 @@ AudioDecoder::emit (shared_ptr<const Film> film, AudioStreamPtr stream, shared_p
shared_ptr<Resampler> resampler;
auto i = _resamplers.find(stream);
- if (i != _resamplers.end ()) {
+ if (i != _resamplers.end()) {
resampler = i->second;
} else {
if (stream->frame_rate() != resampled_rate) {
@@ -128,6 +132,7 @@ AudioDecoder::emit (shared_ptr<const Film> film, AudioStreamPtr stream, shared_p
_positions[stream] += data->frames();
}
+
/** @return Time just after the last thing that was emitted from a given stream */
ContentTime
AudioDecoder::stream_position (shared_ptr<const Film> film, AudioStreamPtr stream) const
@@ -137,6 +142,7 @@ AudioDecoder::stream_position (shared_ptr<const Film> film, AudioStreamPtr strea
return ContentTime::from_frames (i->second, _content->resampled_frame_rate(film));
}
+
boost::optional<ContentTime>
AudioDecoder::position (shared_ptr<const Film> film) const
{
@@ -151,6 +157,7 @@ AudioDecoder::position (shared_ptr<const Film> film) const
return p;
}
+
void
AudioDecoder::seek ()
{
@@ -164,6 +171,7 @@ AudioDecoder::seek ()
}
}
+
void
AudioDecoder::flush ()
{
@@ -181,6 +189,7 @@ AudioDecoder::flush ()
}
}
+
void
AudioDecoder::silence (int milliseconds)
{
diff --git a/src/lib/audio_decoder.h b/src/lib/audio_decoder.h
index 2b6e3f758..754321880 100644
--- a/src/lib/audio_decoder.h
+++ b/src/lib/audio_decoder.h
@@ -18,19 +18,23 @@
*/
+
/** @file src/lib/audio_decoder.h
* @brief Parent class for audio decoders.
*/
+
#ifndef DCPOMATIC_AUDIO_DECODER_H
#define DCPOMATIC_AUDIO_DECODER_H
+
#include "decoder.h"
#include "content_audio.h"
#include "audio_stream.h"
#include "decoder_part.h"
#include <boost/signals2.hpp>
+
class AudioBuffers;
class AudioContent;
class AudioDecoderStream;
@@ -38,6 +42,7 @@ class Log;
class Film;
class Resampler;
+
/** @class AudioDecoder.
* @brief Parent class for audio decoders.
*/
@@ -64,10 +69,11 @@ private:
*/
typedef std::map<AudioStreamPtr, Frame> PositionMap;
PositionMap _positions;
- typedef std::map<AudioStreamPtr, std::shared_ptr<Resampler> > ResamplerMap;
+ typedef std::map<AudioStreamPtr, std::shared_ptr<Resampler>> ResamplerMap;
ResamplerMap _resamplers;
bool _fast;
};
+
#endif
diff --git a/src/lib/cross_windows.cc b/src/lib/cross_windows.cc
index 0ab56bb6b..04ee26271 100644
--- a/src/lib/cross_windows.cc
+++ b/src/lib/cross_windows.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "cross.h"
#include "compose.hpp"
#include "log.h"
@@ -47,21 +48,24 @@ extern "C" {
#include "i18n.h"
+
using std::pair;
-using std::list;
-using std::ifstream;
-using std::string;
-using std::wstring;
-using std::make_pair;
-using std::vector;
using std::cerr;
using std::cout;
-using std::runtime_error;
+using std::ifstream;
+using std::list;
+using std::make_pair;
using std::map;
+using std::runtime_error;
using std::shared_ptr;
+using std::string;
+using std::vector;
+using std::wstring;
using boost::optional;
-static std::vector<pair<HANDLE, string> > locked_volumes;
+
+static std::vector<pair<HANDLE, string>> locked_volumes;
+
/** @param s Number of seconds to sleep for */
void
@@ -70,12 +74,14 @@ dcpomatic_sleep_seconds (int s)
Sleep (s * 1000);
}
+
void
dcpomatic_sleep_milliseconds (int ms)
{
Sleep (ms);
}
+
/** @return A string of CPU information (model name etc.) */
string
cpu_info ()
@@ -110,6 +116,7 @@ cpu_info ()
return info;
}
+
void
run_ffprobe (boost::filesystem::path content, boost::filesystem::path out)
{
@@ -150,7 +157,7 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out)
return;
}
- FILE* o = fopen_boost (out, "w");
+ auto o = fopen_boost (out, "w");
if (!o) {
LOG_ERROR_NC (N_("ffprobe call failed (could not create output file)"));
return;
@@ -175,11 +182,11 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out)
CloseHandle (child_stderr_read);
}
-list<pair<string, string> >
+
+list<pair<string, string>>
mount_info ()
{
- list<pair<string, string> > m;
- return m;
+ return {};
}
@@ -239,12 +246,14 @@ fopen_boost (boost::filesystem::path p, string t)
return _wfopen (p.c_str(), w.c_str ());
}
+
int
dcpomatic_fseek (FILE* stream, int64_t offset, int whence)
{
return _fseeki64 (stream, offset, whence);
}
+
void
Waker::nudge ()
{
@@ -252,11 +261,13 @@ Waker::nudge ()
SetThreadExecutionState (ES_SYSTEM_REQUIRED);
}
+
Waker::Waker ()
{
}
+
Waker::~Waker ()
{
@@ -266,7 +277,7 @@ Waker::~Waker ()
void
start_tool (string executable)
{
- boost::filesystem::path batch = directory_containing_executable() / executable;
+ auto batch = directory_containing_executable() / executable;
STARTUPINFO startup_info;
ZeroMemory (&startup_info, sizeof (startup_info));
@@ -301,6 +312,7 @@ thread_id ()
return (uint64_t) GetCurrentThreadId ();
}
+
static string
wchar_to_utf8 (wchar_t const * s)
{
@@ -312,38 +324,42 @@ wchar_to_utf8 (wchar_t const * s)
return u;
}
+
int
avio_open_boost (AVIOContext** s, boost::filesystem::path file, int flags)
{
return avio_open (s, wchar_to_utf8(file.c_str()).c_str(), flags);
}
+
void
maybe_open_console ()
{
if (Config::instance()->win32_console ()) {
AllocConsole();
- HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
+ auto handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
- FILE* hf_out = _fdopen(hCrt, "w");
+ auto hf_out = _fdopen(hCrt, "w");
setvbuf(hf_out, NULL, _IONBF, 1);
*stdout = *hf_out;
- HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
+ auto handle_in = GetStdHandle(STD_INPUT_HANDLE);
hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
- FILE* hf_in = _fdopen(hCrt, "r");
+ auto hf_in = _fdopen(hCrt, "r");
setvbuf(hf_in, NULL, _IONBF, 128);
*stdin = *hf_in;
}
}
+
boost::filesystem::path
home_directory ()
{
return boost::filesystem::path(getenv("HOMEDRIVE")) / boost::filesystem::path(getenv("HOMEPATH"));
}
+
/** @return true if this process is a 32-bit one running on a 64-bit-capable OS */
bool
running_32_on_64 ()
@@ -353,6 +369,7 @@ running_32_on_64 ()
return p;
}
+
static optional<string>
get_friendly_name (HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
{
@@ -367,10 +384,12 @@ get_friendly_name (HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
return wchar_to_utf8 (buffer);
}
+
static const GUID GUID_DEVICE_INTERFACE_DISK = {
0x53F56307L, 0xB6BF, 0x11D0, { 0x94, 0xF2, 0x00, 0xA0, 0xC9, 0x1E, 0xFB, 0x8B }
};
+
static optional<int>
get_device_number (HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
{
@@ -379,7 +398,7 @@ get_device_number (HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
SP_DEVICE_INTERFACE_DATA device_interface_data;
device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
- BOOL r = SetupDiEnumDeviceInterfaces (device_info, device_info_data, &GUID_DEVICE_INTERFACE_DISK, 0, &device_interface_data);
+ auto r = SetupDiEnumDeviceInterfaces (device_info, device_info_data, &GUID_DEVICE_INTERFACE_DISK, 0, &device_interface_data);
if (!r) {
LOG_DISK("SetupDiEnumDeviceInterfaces failed (%1)", GetLastError());
return optional<int>();
@@ -407,7 +426,7 @@ get_device_number (HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
/* Open it. We would not be allowed GENERIC_READ access here but specifying 0 for
dwDesiredAccess allows us to query some metadata.
*/
- HANDLE device = CreateFileW (
+ auto device = CreateFileW (
device_detail_data->DevicePath, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0
@@ -430,13 +449,15 @@ get_device_number (HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
CloseHandle (device);
if (!r) {
- return optional<int>();
+ return {};
}
return device_number.DeviceNumber;
}
-typedef map<int, vector<boost::filesystem::path> > MountPoints;
+
+typedef map<int, vector<boost::filesystem::path>> MountPoints;
+
/** Take a volume path (with a trailing \) and add any disk numbers related to that volume
* to @ref disks.
@@ -463,7 +484,7 @@ add_volume_mount_points (wchar_t* volume, MountPoints& mount_points)
DCPOMATIC_ASSERT (len > 0);
volume[len - 1] = L'\0';
- HANDLE handle = CreateFileW (
+ auto handle = CreateFileW (
volume, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0
@@ -483,13 +504,14 @@ add_volume_mount_points (wchar_t* volume, MountPoints& mount_points)
mount_points[extents.Extents[0].DiskNumber] = mp;
}
+
MountPoints
find_mount_points ()
{
MountPoints mount_points;
wchar_t volume_name[512];
- HANDLE volume = FindFirstVolumeW (volume_name, sizeof(volume_name) / sizeof(wchar_t));
+ auto volume = FindFirstVolumeW (volume_name, sizeof(volume_name) / sizeof(wchar_t));
if (volume == INVALID_HANDLE_VALUE) {
return MountPoints();
}
@@ -506,15 +528,16 @@ find_mount_points ()
return mount_points;
}
+
vector<Drive>
Drive::get ()
{
vector<Drive> drives;
- MountPoints mount_points = find_mount_points ();
+ auto mount_points = find_mount_points ();
/* Get a `device information set' containing information about all disks */
- HDEVINFO device_info = SetupDiGetClassDevsA (&GUID_DEVICE_INTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
+ auto device_info = SetupDiGetClassDevsA (&GUID_DEVICE_INTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (device_info == INVALID_HANDLE_VALUE) {
LOG_DISK_NC ("SetupDiClassDevsA failed");
return drives;
@@ -534,8 +557,8 @@ Drive::get ()
}
++i;
- optional<string> const friendly_name = get_friendly_name (device_info, &device_info_data);
- optional<int> device_number = get_device_number (device_info, &device_info_data);
+ auto const friendly_name = get_friendly_name (device_info, &device_info_data);
+ auto device_number = get_device_number (device_info, &device_info_data);
if (!device_number) {
continue;
}
@@ -562,8 +585,8 @@ Drive::get ()
LOG_DISK("Having a look through %1 locked volumes", locked_volumes.size());
bool locked = false;
- for (vector<pair<HANDLE, string> >::const_iterator i = locked_volumes.begin(); i != locked_volumes.end(); ++i) {
- if (i->second == physical_drive) {
+ for (auto const& i: locked_volumes) {
+ if (i.second == physical_drive) {
locked = true;
}
}
@@ -619,11 +642,12 @@ config_path ()
return p;
}
+
void
disk_write_finished ()
{
- for (vector<pair<HANDLE, string> >::const_iterator i = locked_volumes.begin(); i != locked_volumes.end(); ++i) {
- CloseHandle (i->first);
+ for (auto const& i: locked_volumes) {
+ CloseHandle (i.first);
}
}
diff --git a/src/lib/dcp.cc b/src/lib/dcp.cc
index 06e3e15d5..d99c32bf3 100644
--- a/src/lib/dcp.cc
+++ b/src/lib/dcp.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,19 +18,20 @@
*/
-#include "dcp.h"
-#include "config.h"
-#include "film.h"
-#include "log.h"
-#include "dcpomatic_log.h"
+
#include "compose.hpp"
+#include "dcp.h"
#include "dcp_content.h"
+#include "dcpomatic_log.h"
+#include "log.h"
+#include "util.h"
#include <dcp/dcp.h>
#include <dcp/decrypted_kdm.h>
#include <dcp/exceptions.h>
#include "i18n.h"
+
using std::list;
using std::string;
using std::shared_ptr;
@@ -40,7 +41,7 @@ using std::vector;
/** Find all the CPLs in our directories, cross-add assets and return the CPLs */
-list<shared_ptr<dcp::CPL> >
+list<shared_ptr<dcp::CPL>>
DCP::cpls () const
{
list<shared_ptr<dcp::DCP>> dcps;
@@ -77,7 +78,7 @@ DCP::cpls () const
}
if (_dcp_content->kdm ()) {
- dcp::DecryptedKDM k = decrypt_kdm_with_helpful_error (_dcp_content->kdm().get());
+ auto k = decrypt_kdm_with_helpful_error (_dcp_content->kdm().get());
for (auto i: dcps) {
i->add (k);
}
diff --git a/src/lib/dcp.h b/src/lib/dcp.h
index d72ce6833..d8e0aec27 100644
--- a/src/lib/dcp.h
+++ b/src/lib/dcp.h
@@ -18,19 +18,27 @@
*/
+
#ifndef DCPOMATIC_DCP_H
#define DCPOMATIC_DCP_H
-#include <dcp/cpl.h>
+
#include <list>
-#include <iostream>
+#include <memory>
+
+
+namespace dcp {
+ class CPL;
+}
+
class DCPContent;
+
class DCP
{
public:
- std::list<std::shared_ptr<dcp::CPL> > cpls () const;
+ std::list<std::shared_ptr<dcp::CPL>> cpls () const;
protected:
explicit DCP (std::shared_ptr<const DCPContent> content, bool tolerant)
@@ -44,4 +52,5 @@ private:
bool _tolerant;
};
+
#endif
diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h
index 00a31a7a7..9e7191b1e 100644
--- a/src/lib/dcpomatic_time.h
+++ b/src/lib/dcpomatic_time.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,13 +18,16 @@
*/
+
/** @file src/lib/dcpomatic_time.h
* @brief Types to describe time.
*/
+
#ifndef DCPOMATIC_TIME_H
#define DCPOMATIC_TIME_H
+
#include "frame_rate_change.h"
#include "dcpomatic_assert.h"
#include <boost/optional.hpp>
@@ -34,9 +37,11 @@
#include <iomanip>
#include <cstdio>
+
struct dcpomatic_time_ceil_test;
struct dcpomatic_time_floor_test;
+
namespace dcpomatic {
@@ -156,15 +161,15 @@ public:
* @param r Sampling rate.
*/
Time<S, O> ceil (double r) const {
- return Time<S, O> (llrint (HZ * frames_ceil(r) / r));
+ return Time<S, O> (llrint(HZ * frames_ceil(r) / r));
}
Time<S, O> floor (double r) const {
- return Time<S, O> (llrint (HZ * frames_floor(r) / r));
+ return Time<S, O> (llrint(HZ * frames_floor(r) / r));
}
Time<S, O> round (double r) const {
- return Time<S, O> (llrint (HZ * frames_round(r) / r));
+ return Time<S, O> (llrint(HZ * frames_round(r) / r));
}
double seconds () const {
@@ -172,7 +177,7 @@ public:
}
Time<S, O> abs () const {
- return Time<S, O> (std::abs (_t));
+ return Time<S, O> (std::abs(_t));
}
template <typename T>
@@ -231,7 +236,6 @@ public:
return buffer;
}
-
static Time<S, O> from_seconds (double s) {
return Time<S, O> (llrint (s * HZ));
}
@@ -263,9 +267,11 @@ private:
Type _t;
};
+
class ContentTimeDifferentiator {};
class DCPTimeDifferentiator {};
+
/* Specializations for the two allowed explicit conversions */
template<>
@@ -274,6 +280,7 @@ Time<ContentTimeDifferentiator, DCPTimeDifferentiator>::Time (Time<DCPTimeDiffer
template<>
Time<DCPTimeDifferentiator, ContentTimeDifferentiator>::Time (Time<ContentTimeDifferentiator, DCPTimeDifferentiator> d, FrameRateChange f);
+
/** Time relative to the start or position of a piece of content in its native frame rate */
typedef Time<ContentTimeDifferentiator, DCPTimeDifferentiator> ContentTime;
/** Time relative to the start of the output DCP in its frame rate */
@@ -303,12 +310,12 @@ public:
return TimePeriod<T> (from + o, to + o);
}
- boost::optional<TimePeriod<T> > overlap (TimePeriod<T> const & other) const {
+ boost::optional<TimePeriod<T>> overlap (TimePeriod<T> const & other) const {
T const max_from = std::max (from, other.from);
T const min_to = std::min (to, other.to);
if (max_from >= min_to) {
- return boost::optional<TimePeriod<T> > ();
+ return {};
}
return TimePeriod<T> (max_from, min_to);
@@ -334,36 +341,37 @@ public:
}
};
+
/** @param A Period which is subtracted from.
* @param B Periods to subtract from `A', must be in ascending order of start time and must not overlap.
*/
template <class T>
-std::list<TimePeriod<T> > subtract (TimePeriod<T> A, std::list<TimePeriod<T> > const & B)
+std::list<TimePeriod<T>> subtract (TimePeriod<T> A, std::list<TimePeriod<T>> const & B)
{
- std::list<TimePeriod<T> > result;
+ std::list<TimePeriod<T>> result;
result.push_back (A);
for (auto i: B) {
- std::list<TimePeriod<T> > new_result;
+ std::list<TimePeriod<T>> new_result;
for (auto j: result) {
- boost::optional<TimePeriod<T> > ov = i.overlap (j);
+ auto ov = i.overlap (j);
if (ov) {
if (*ov == i) {
/* A contains all of B */
if (i.from != j.from) {
- new_result.push_back (TimePeriod<T> (j.from, i.from));
+ new_result.push_back (TimePeriod<T>(j.from, i.from));
}
if (i.to != j.to) {
- new_result.push_back (TimePeriod<T> (i.to, j.to));
+ new_result.push_back (TimePeriod<T>(i.to, j.to));
}
} else if (*ov == j) {
/* B contains all of A */
} else if (i.from < j.from) {
/* B overlaps start of A */
- new_result.push_back (TimePeriod<T> (i.to, j.to));
+ new_result.push_back (TimePeriod<T>(i.to, j.to));
} else if (i.to > j.to) {
/* B overlaps end of A */
- new_result.push_back (TimePeriod<T> (j.from, i.from));
+ new_result.push_back (TimePeriod<T>(j.from, i.from));
}
} else {
new_result.push_back (j);
@@ -375,9 +383,11 @@ std::list<TimePeriod<T> > subtract (TimePeriod<T> A, std::list<TimePeriod<T> > c
return result;
}
+
typedef TimePeriod<ContentTime> ContentTimePeriod;
typedef TimePeriod<DCPTime> DCPTimePeriod;
+
DCPTime min (DCPTime a, DCPTime b);
DCPTime max (DCPTime a, DCPTime b);
ContentTime min (ContentTime a, ContentTime b);
@@ -386,6 +396,8 @@ std::string to_string (ContentTime t);
std::string to_string (DCPTime t);
std::string to_string (DCPTimePeriod p);
+
}
+
#endif
diff --git a/src/lib/dcpomatic_time_coalesce.h b/src/lib/dcpomatic_time_coalesce.h
index 56f82bcb6..015326bdd 100644
--- a/src/lib/dcpomatic_time_coalesce.h
+++ b/src/lib/dcpomatic_time_coalesce.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2017-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,17 +18,20 @@
*/
+
#include "dcpomatic_time.h"
#include <iostream>
+
namespace dcpomatic {
+
/** @param periods Set of periods in ascending order of from time */
template <class T>
-std::list<TimePeriod<T> > coalesce (std::list<TimePeriod<T> > periods)
+std::list<TimePeriod<T>> coalesce (std::list<TimePeriod<T>> periods)
{
bool did_something;
- std::list<TimePeriod<T> > coalesced;
+ std::list<TimePeriod<T>> coalesced;
do {
coalesced.clear ();
did_something = false;
@@ -49,4 +52,5 @@ std::list<TimePeriod<T> > coalesce (std::list<TimePeriod<T> > periods)
return periods;
}
+
}
diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc
index ed867b475..39951d139 100644
--- a/src/lib/ffmpeg_examiner.cc
+++ b/src/lib/ffmpeg_examiner.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "dcpomatic_log.h"
#include "ffmpeg_examiner.h"
#include "ffmpeg_content.h"
@@ -40,11 +41,13 @@ DCPOMATIC_ENABLE_WARNINGS
#include "i18n.h"
-using std::string;
+
using std::cout;
+using std::make_shared;
using std::max;
-using std::vector;
using std::shared_ptr;
+using std::string;
+using std::vector;
using boost::optional;
using namespace dcpomatic;
@@ -65,7 +68,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
/* Find audio and subtitle streams */
for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
- AVStream* s = _format_context->streams[i];
+ auto s = _format_context->streams[i];
DCPOMATIC_DISABLE_WARNINGS
if (s->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
@@ -82,15 +85,13 @@ DCPOMATIC_DISABLE_WARNINGS
DCPOMATIC_ASSERT (s->codec->codec->name);
_audio_streams.push_back (
- shared_ptr<FFmpegAudioStream> (
- new FFmpegAudioStream (
- stream_name (s),
- s->codec->codec->name,
- s->id,
- s->codec->sample_rate,
- llrint ((double (_format_context->duration) / AV_TIME_BASE) * s->codec->sample_rate),
- s->codec->channels
- )
+ make_shared<FFmpegAudioStream>(
+ stream_name (s),
+ s->codec->codec->name,
+ s->id,
+ s->codec->sample_rate,
+ llrint ((double(_format_context->duration) / AV_TIME_BASE) * s->codec->sample_rate),
+ s->codec->channels
)
);
@@ -295,12 +296,14 @@ FFmpegExaminer::video_frame_rate () const
return av_q2d(av_guess_frame_rate(_format_context, _format_context->streams[_video_stream.get()], 0));
}
+
dcp::Size
FFmpegExaminer::video_size () const
{
return dcp::Size (video_codec_context()->width, video_codec_context()->height);
}
+
/** @return Length according to our content's header */
Frame
FFmpegExaminer::video_length () const
@@ -308,11 +311,12 @@ FFmpegExaminer::video_length () const
return max (Frame (1), _video_length);
}
+
optional<double>
FFmpegExaminer::sample_aspect_ratio () const
{
DCPOMATIC_ASSERT (_video_stream);
- AVRational sar = av_guess_sample_aspect_ratio (_format_context, _format_context->streams[_video_stream.get()], 0);
+ auto sar = av_guess_sample_aspect_ratio (_format_context, _format_context->streams[_video_stream.get()], 0);
if (sar.num == 0) {
/* I assume this means that we don't know */
return {};
@@ -320,6 +324,7 @@ FFmpegExaminer::sample_aspect_ratio () const
return double (sar.num) / sar.den;
}
+
string
FFmpegExaminer::subtitle_stream_name (AVStream* s) const
{
@@ -332,18 +337,19 @@ FFmpegExaminer::subtitle_stream_name (AVStream* s) const
return n;
}
+
string
FFmpegExaminer::stream_name (AVStream* s) const
{
string n;
if (s->metadata) {
- AVDictionaryEntry const * lang = av_dict_get (s->metadata, "language", 0, 0);
+ auto const lang = av_dict_get (s->metadata, "language", 0, 0);
if (lang) {
n = lang->value;
}
- AVDictionaryEntry const * title = av_dict_get (s->metadata, "title", 0, 0);
+ auto const title = av_dict_get (s->metadata, "title", 0, 0);
if (title) {
if (!n.empty()) {
n += " ";
@@ -355,18 +361,20 @@ FFmpegExaminer::stream_name (AVStream* s) const
return n;
}
+
optional<int>
FFmpegExaminer::bits_per_pixel () const
{
if (video_codec_context()->pix_fmt == -1) {
- return optional<int>();
+ return {};
}
- AVPixFmtDescriptor const * d = av_pix_fmt_desc_get (video_codec_context()->pix_fmt);
+ auto const d = av_pix_fmt_desc_get (video_codec_context()->pix_fmt);
DCPOMATIC_ASSERT (d);
return av_get_bits_per_pixel (d);
}
+
bool
FFmpegExaminer::yuv () const
{
@@ -448,12 +456,14 @@ FFmpegExaminer::yuv () const
}
}
+
bool
FFmpegExaminer::has_video () const
{
- return static_cast<bool> (_video_stream);
+ return static_cast<bool>(_video_stream);
}
+
VideoRange
FFmpegExaminer::range () const
{
diff --git a/src/lib/ffmpeg_examiner.h b/src/lib/ffmpeg_examiner.h
index 0884a6fb8..793460f9b 100644
--- a/src/lib/ffmpeg_examiner.h
+++ b/src/lib/ffmpeg_examiner.h
@@ -18,20 +18,22 @@
*/
+
#include "ffmpeg.h"
#include "video_examiner.h"
#include <boost/optional.hpp>
-struct AVStream;
+struct AVStream;
class FFmpegAudioStream;
class FFmpegSubtitleStream;
class Job;
+
class FFmpegExaminer : public FFmpeg, public VideoExaminer
{
public:
- FFmpegExaminer (std::shared_ptr<const FFmpegContent>, std::shared_ptr<Job> job = std::shared_ptr<Job> ());
+ FFmpegExaminer (std::shared_ptr<const FFmpegContent>, std::shared_ptr<Job> job = std::shared_ptr<Job>());
bool has_video () const;
@@ -41,11 +43,11 @@ public:
boost::optional<double> sample_aspect_ratio () const;
bool yuv () const;
- std::vector<std::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
+ std::vector<std::shared_ptr<FFmpegSubtitleStream>> subtitle_streams () const {
return _subtitle_streams;
}
- std::vector<std::shared_ptr<FFmpegAudioStream> > audio_streams () const {
+ std::vector<std::shared_ptr<FFmpegAudioStream>> audio_streams () const {
return _audio_streams;
}
@@ -89,8 +91,8 @@ private:
std::string subtitle_stream_name (AVStream* s) const;
boost::optional<dcpomatic::ContentTime> frame_time (AVStream* s) const;
- std::vector<std::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
- std::vector<std::shared_ptr<FFmpegAudioStream> > _audio_streams;
+ std::vector<std::shared_ptr<FFmpegSubtitleStream>> _subtitle_streams;
+ std::vector<std::shared_ptr<FFmpegAudioStream>> _audio_streams;
boost::optional<dcpomatic::ContentTime> _first_video;
/** Video length, either obtained from the header or derived by running
* through the whole file.
@@ -115,6 +117,6 @@ private:
dcpomatic::ContentTime time;
};
- typedef std::map<std::shared_ptr<FFmpegSubtitleStream>, boost::optional<SubtitleStart> > LastSubtitleMap;
+ typedef std::map<std::shared_ptr<FFmpegSubtitleStream>, boost::optional<SubtitleStart>> LastSubtitleMap;
LastSubtitleMap _last_subtitle_start;
};
diff --git a/src/lib/j2k_encoder.cc b/src/lib/j2k_encoder.cc
index a7fa657f8..c2553854b 100644
--- a/src/lib/j2k_encoder.cc
+++ b/src/lib/j2k_encoder.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,10 +18,12 @@
*/
+
/** @file src/j2k_encoder.cc
* @brief J2K encoder class.
*/
+
#include "j2k_encoder.h"
#include "util.h"
#include "film.h"
@@ -41,6 +43,7 @@
#include "i18n.h"
+
using std::list;
using std::cout;
using std::exception;
@@ -51,6 +54,7 @@ using boost::optional;
using dcp::Data;
using namespace dcpomatic;
+
/** @param film Film that we are encoding.
* @param writer Writer that we are using.
*/
@@ -62,21 +66,24 @@ J2KEncoder::J2KEncoder (shared_ptr<const Film> film, shared_ptr<Writer> writer)
servers_list_changed ();
}
+
J2KEncoder::~J2KEncoder ()
{
boost::mutex::scoped_lock lm (_threads_mutex);
terminate_threads ();
}
+
void
J2KEncoder::begin ()
{
- weak_ptr<J2KEncoder> wp = shared_from_this ();
+ auto wp = shared_from_this ();
_server_found_connection = EncodeServerFinder::instance()->ServersListChanged.connect (
boost::bind (&J2KEncoder::call_servers_list_changed, wp)
);
}
+
/* We don't want the servers-list-changed callback trying to do things
during destruction of J2KEncoder, and I think this is the neatest way
to achieve that.
@@ -90,6 +97,7 @@ J2KEncoder::call_servers_list_changed (weak_ptr<J2KEncoder> encoder)
}
}
+
void
J2KEncoder::end ()
{
@@ -142,6 +150,7 @@ J2KEncoder::end ()
}
}
+
/** @return an estimate of the current number of frames we are encoding per second,
* if known.
*/
@@ -151,6 +160,7 @@ J2KEncoder::current_encoding_rate () const
return _history.rate ();
}
+
/** @return Number of video frames that have been queued for encoding */
int
J2KEncoder::video_frames_enqueued () const
@@ -162,6 +172,7 @@ J2KEncoder::video_frames_enqueued () const
return _last_player_video_time->frames_floor (_film->video_frame_rate ());
}
+
/** Should be called when a frame has been encoded successfully */
void
J2KEncoder::frame_done ()
@@ -169,6 +180,7 @@ J2KEncoder::frame_done ()
_history.event ();
}
+
/** Called to request encoding of the next video frame in the DCP. This is called in order,
* so each time the supplied frame is the one after the previous one.
* pv represents one video frame, and could be empty if there is nothing to encode
@@ -266,6 +278,7 @@ J2KEncoder::terminate_threads ()
_threads.reset ();
}
+
void
J2KEncoder::encoder_thread (optional<EncodeServerDescription> server)
try
@@ -373,6 +386,7 @@ catch (...)
_full_condition.notify_all ();
}
+
void
J2KEncoder::servers_list_changed ()
{
diff --git a/src/lib/j2k_encoder.h b/src/lib/j2k_encoder.h
index 98cca6ba2..06b4d429c 100644
--- a/src/lib/j2k_encoder.h
+++ b/src/lib/j2k_encoder.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,13 +18,16 @@
*/
+
#ifndef DCPOMATIC_J2K_ENCODER_H
#define DCPOMATIC_J2K_ENCODER_H
+
/** @file src/j2k_encoder.h
* @brief J2KEncoder class.
*/
+
#include "util.h"
#include "cross.h"
#include "event_history.h"
@@ -37,6 +40,7 @@
#include <list>
#include <stdint.h>
+
class Film;
class EncodeServerDescription;
class DCPVideo;
@@ -44,13 +48,13 @@ class Writer;
class Job;
class PlayerVideo;
+
/** @class J2KEncoder
* @brief Class to manage encoding to J2K.
*
* This class keeps a queue of frames to be encoded and distributes
* the work around threads and encoding servers.
*/
-
class J2KEncoder : public boost::noncopyable, public ExceptionStore, public std::enable_shared_from_this<J2KEncoder>
{
public:
@@ -89,7 +93,7 @@ private:
std::shared_ptr<boost::thread_group> _threads;
mutable boost::mutex _queue_mutex;
- std::list<std::shared_ptr<DCPVideo> > _queue;
+ std::list<std::shared_ptr<DCPVideo>> _queue;
/** condition to manage thread wakeups when we have nothing to do */
boost::condition _empty_condition;
/** condition to manage thread wakeups when we have too much to do */
@@ -104,4 +108,5 @@ private:
boost::signals2::scoped_connection _server_found_connection;
};
+
#endif
diff --git a/src/lib/json_server.cc b/src/lib/json_server.cc
index 9c1034a68..dd56b3124 100644
--- a/src/lib/json_server.cc
+++ b/src/lib/json_server.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "json_server.h"
#include "job_manager.h"
#include "job.h"
@@ -30,6 +31,7 @@
#include <boost/thread.hpp>
#include <iostream>
+
using std::string;
using std::cout;
using std::map;
@@ -40,8 +42,10 @@ using std::dynamic_pointer_cast;
using boost::asio::ip::tcp;
using dcp::raw_convert;
+
#define MAX_LENGTH 512
+
enum State {
AWAITING_G,
AWAITING_E,
@@ -50,16 +54,18 @@ enum State {
READING_URL,
};
+
JSONServer::JSONServer (int port)
{
#ifdef DCPOMATIC_LINUX
- thread* t = new thread (boost::bind (&JSONServer::run, this, port));
+ auto t = new thread (boost::bind (&JSONServer::run, this, port));
pthread_setname_np (t->native_handle(), "json-server");
#else
new thread (boost::bind (&JSONServer::run, this, port));
#endif
}
+
void
JSONServer::run (int port)
try
@@ -82,6 +88,7 @@ catch (...)
}
+
void
JSONServer::handle (shared_ptr<tcp::socket> socket)
{
@@ -97,11 +104,11 @@ JSONServer::handle (shared_ptr<tcp::socket> socket)
break;
}
- char* p = data;
- char* e = data + len;
+ auto p = data;
+ auto e = data + len;
while (p != e) {
- State old_state = state;
+ auto old_state = state;
switch (state) {
case AWAITING_G:
if (*p == 'G') {
@@ -143,14 +150,15 @@ JSONServer::handle (shared_ptr<tcp::socket> socket)
}
}
+
void
JSONServer::request (string url, shared_ptr<tcp::socket> socket)
{
cout << "request: " << url << "\n";
- map<string, string> r = split_get_request (url);
- for (map<string, string>::iterator i = r.begin(); i != r.end(); ++i) {
- cout << i->first << " => " << i->second << "\n";
+ auto r = split_get_request (url);
+ for (auto const& i: r) {
+ cout << i.first << " => " << i.second << "\n";
}
string action;
@@ -161,11 +169,10 @@ JSONServer::request (string url, shared_ptr<tcp::socket> socket)
string json;
if (action == "status") {
- list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
+ auto jobs = JobManager::instance()->get();
json += "{ \"jobs\": [";
- for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
-
+ for (auto i = jobs.cbegin(); i != jobs.cend(); ++i) {
json += "{ ";
if ((*i)->film()) {
@@ -173,7 +180,7 @@ JSONServer::request (string url, shared_ptr<tcp::socket> socket)
}
json += "\"name\": \"" + (*i)->json_name() + "\", ";
- if ((*i)->progress ()) {
+ if ((*i)->progress()) {
json += "\"progress\": " + raw_convert<string>((*i)->progress().get()) + ", ";
} else {
json += "\"progress\": unknown, ";
@@ -181,7 +188,7 @@ JSONServer::request (string url, shared_ptr<tcp::socket> socket)
json += "\"status\": \"" + (*i)->json_status() + "\"";
json += " }";
- list<shared_ptr<Job> >::iterator j = i;
+ auto j = i;
++j;
if (j != jobs.end ()) {
json += ", ";
@@ -196,5 +203,5 @@ JSONServer::request (string url, shared_ptr<tcp::socket> socket)
"\r\n"
+ json + "\r\n";
cout << "reply: " << json << "\n";
- boost::asio::write (*socket, boost::asio::buffer (reply.c_str(), reply.length()));
+ boost::asio::write (*socket, boost::asio::buffer(reply.c_str(), reply.length()));
}
diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc
index 92c95a401..fbd2e4bd4 100644
--- a/src/lib/kdm_with_metadata.cc
+++ b/src/lib/kdm_with_metadata.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "kdm_with_metadata.h"
#include "cinema.h"
#include "screen.h"
@@ -31,6 +32,7 @@
#include "i18n.h"
+
using std::string;
using std::cout;
using std::list;
@@ -38,6 +40,7 @@ using std::shared_ptr;
using boost::optional;
using boost::function;
+
int
write_files (
list<KDMWithMetadataPtr> kdms,
@@ -64,7 +67,7 @@ write_files (
/* Write KDMs to the specified directory */
for (auto i: kdms) {
- boost::filesystem::path out = directory / careful_string_filter(name_format.get(i->name_values(), ".xml"));
+ auto out = directory / careful_string_filter(name_format.get(i->name_values(), ".xml"));
if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
i->kdm_as_xml (out);
++written;
@@ -78,9 +81,9 @@ write_files (
optional<string>
KDMWithMetadata::get (char k) const
{
- dcp::NameFormat::Map::const_iterator i = _name_values.find (k);
+ auto i = _name_values.find (k);
if (i == _name_values.end()) {
- return optional<string>();
+ return {};
}
return i->second;
@@ -93,7 +96,7 @@ make_zip_file (list<KDMWithMetadataPtr> kdms, boost::filesystem::path zip_file,
Zipper zipper (zip_file);
for (auto i: kdms) {
- string const name = careful_string_filter(name_format.get(i->name_values(), ".xml"));
+ auto const name = careful_string_filter(name_format.get(i->name_values(), ".xml"));
zipper.add (name, i->kdm_as_xml());
}
@@ -104,14 +107,14 @@ make_zip_file (list<KDMWithMetadataPtr> kdms, boost::filesystem::path zip_file,
/** Collect a list of KDMWithMetadatas into a list of lists so that
* each list contains the KDMs for one list.
*/
-list<list<KDMWithMetadataPtr> >
+list<list<KDMWithMetadataPtr>>
collect (list<KDMWithMetadataPtr> kdms)
{
- list<list<KDMWithMetadataPtr> > grouped;
+ list<list<KDMWithMetadataPtr>> grouped;
for (auto i: kdms) {
- list<list<KDMWithMetadataPtr> >::iterator j = grouped.begin ();
+ auto j = grouped.begin ();
while (j != grouped.end()) {
if (j->front()->group() == i->group()) {
@@ -134,7 +137,7 @@ collect (list<KDMWithMetadataPtr> kdms)
/** Write one directory per list into another directory */
int
write_directories (
- list<list<KDMWithMetadataPtr> > kdms,
+ list<list<KDMWithMetadataPtr>> kdms,
boost::filesystem::path directory,
dcp::NameFormat container_name_format,
dcp::NameFormat filename_format,
@@ -160,7 +163,7 @@ write_directories (
/** Write one ZIP file per cinema into a directory */
int
write_zip_files (
- list<list<KDMWithMetadataPtr> > kdms,
+ list<list<KDMWithMetadataPtr>> kdms,
boost::filesystem::path directory,
dcp::NameFormat container_name_format,
dcp::NameFormat filename_format,
@@ -170,7 +173,7 @@ write_zip_files (
int written = 0;
for (auto const& i: kdms) {
- boost::filesystem::path path = directory;
+ auto path = directory;
path /= container_name_format.get(i.front()->name_values(), ".zip", "s");
if (!boost::filesystem::exists (path) || confirm_overwrite (path)) {
if (boost::filesystem::exists (path)) {
@@ -195,13 +198,13 @@ write_zip_files (
*/
void
email (
- list<list<KDMWithMetadataPtr> > kdms,
+ list<list<KDMWithMetadataPtr>> kdms,
dcp::NameFormat container_name_format,
dcp::NameFormat filename_format,
string cpl_name
)
{
- Config* config = Config::instance ();
+ auto config = Config::instance ();
if (config->mail_server().empty()) {
throw NetworkError (_("No mail server configured in preferences"));
@@ -213,18 +216,18 @@ email (
continue;
}
- boost::filesystem::path zip_file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
+ auto zip_file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
boost::filesystem::create_directories (zip_file);
zip_file /= container_name_format.get(i.front()->name_values(), ".zip");
make_zip_file (i, zip_file, filename_format);
- string subject = config->kdm_subject();
+ auto subject = config->kdm_subject();
boost::algorithm::replace_all (subject, "$CPL_NAME", cpl_name);
boost::algorithm::replace_all (subject, "$START_TIME", i.front()->get('b').get_value_or(""));
boost::algorithm::replace_all (subject, "$END_TIME", i.front()->get('e').get_value_or(""));
boost::algorithm::replace_all (subject, "$CINEMA_NAME", i.front()->get('c').get_value_or(""));
- string body = config->kdm_email().c_str();
+ auto body = config->kdm_email();
boost::algorithm::replace_all (body, "$CPL_NAME", cpl_name);
boost::algorithm::replace_all (body, "$START_TIME", i.front()->get('b').get_value_or(""));
boost::algorithm::replace_all (body, "$END_TIME", i.front()->get('e').get_value_or(""));
@@ -232,7 +235,7 @@ email (
string screens;
for (auto j: i) {
- optional<string> screen_name = j->get('n');
+ auto screen_name = j->get('n');
if (screen_name) {
screens += *screen_name + ", ";
}
@@ -244,16 +247,14 @@ email (
for (auto i: config->kdm_cc()) {
email.add_cc (i);
}
- if (!config->kdm_bcc().empty ()) {
- email.add_bcc (config->kdm_bcc ());
+ if (!config->kdm_bcc().empty()) {
+ email.add_bcc (config->kdm_bcc());
}
email.add_attachment (zip_file, container_name_format.get(i.front()->name_values(), ".zip"), "application/zip");
- Config* c = Config::instance ();
-
try {
- email.send (c->mail_server(), c->mail_port(), c->mail_protocol(), c->mail_user(), c->mail_password());
+ email.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password());
} catch (...) {
boost::filesystem::remove (zip_file);
dcpomatic_log->log ("Email content follows", LogEntry::TYPE_DEBUG_EMAIL);
diff --git a/src/lib/kdm_with_metadata.h b/src/lib/kdm_with_metadata.h
index fc80a8743..99c2ef8dc 100644
--- a/src/lib/kdm_with_metadata.h
+++ b/src/lib/kdm_with_metadata.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,14 +18,18 @@
*/
+
#ifndef DCPOMATIC_KDM_WITH_METADATA_H
#define DCPOMATIC_KDM_WITH_METADATA_H
+
#include <dcp/encrypted_kdm.h>
#include <dcp/name_format.h>
+
class Cinema;
+
class KDMWithMetadata
{
public:
@@ -78,11 +82,11 @@ int write_files (
void make_zip_file (std::list<KDMWithMetadataPtr> kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format);
-std::list<std::list<KDMWithMetadataPtr> > collect (std::list<KDMWithMetadataPtr> kdms);
+std::list<std::list<KDMWithMetadataPtr>> collect (std::list<KDMWithMetadataPtr> kdms);
int write_directories (
- std::list<std::list<KDMWithMetadataPtr> > kdms,
+ std::list<std::list<KDMWithMetadataPtr>> kdms,
boost::filesystem::path directory,
dcp::NameFormat container_name_format,
dcp::NameFormat filename_format,
@@ -91,7 +95,7 @@ int write_directories (
int write_zip_files (
- std::list<std::list<KDMWithMetadataPtr> > kdms,
+ std::list<std::list<KDMWithMetadataPtr>> kdms,
boost::filesystem::path directory,
dcp::NameFormat container_name_format,
dcp::NameFormat filename_format,
@@ -100,7 +104,7 @@ int write_zip_files (
void email (
- std::list<std::list<KDMWithMetadataPtr> > kdms,
+ std::list<std::list<KDMWithMetadataPtr>> kdms,
dcp::NameFormat container_name_format,
dcp::NameFormat filename_format,
std::string cpl_name
diff --git a/src/lib/player_text.h b/src/lib/player_text.h
index cd4be984c..45c8bf589 100644
--- a/src/lib/player_text.h
+++ b/src/lib/player_text.h
@@ -38,7 +38,7 @@ class PlayerText
{
public:
void add_fonts (std::list<std::shared_ptr<dcpomatic::Font>> fonts_);
- std::list<std::shared_ptr<dcpomatic::Font> > fonts;
+ std::list<std::shared_ptr<dcpomatic::Font>> fonts;
/** BitmapTexts, with their rectangles transformed as specified by their content */
std::list<BitmapText> bitmap;
diff --git a/src/lib/rect.h b/src/lib/rect.h
index 4851ad007..5f807f499 100644
--- a/src/lib/rect.h
+++ b/src/lib/rect.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,18 +18,22 @@
*/
+
#ifndef DCPOMATIC_RECT_H
#define DCPOMATIC_RECT_H
+
#include "position.h"
#include <boost/optional.hpp>
#include <algorithm>
+
/* Put this inside a namespace as Apple put a Rect in the global namespace */
namespace dcpomatic
{
+
/** @struct Rect
* @brief A rectangle.
*/
@@ -69,7 +73,7 @@ public:
return Position<T> (x, y);
}
- boost::optional<Rect<T> > intersection (Rect<T> const & other) const
+ boost::optional<Rect<T>> intersection (Rect<T> const & other) const
{
/* This isn't exactly the paragon of mathematical precision */
@@ -83,7 +87,7 @@ public:
);
if (r.width < 0 || r.height < 0) {
- return boost::optional<Rect<T> > ();
+ return {};
}
return r;
@@ -114,6 +118,8 @@ public:
}
};
+
}
+
#endif
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc
index 2272d3506..d4d827a6b 100644
--- a/src/lib/render_text.cc
+++ b/src/lib/render_text.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,14 +18,15 @@
*/
-#include "render_text.h"
-#include "types.h"
-#include "image.h"
+
#include "cross.h"
-#include "font.h"
#include "dcpomatic_assert.h"
-#include "warnings.h"
+#include "font.h"
+#include "image.h"
+#include "render_text.h"
+#include "types.h"
#include "util.h"
+#include "warnings.h"
#include <dcp/raw_convert.h>
#include <fontconfig/fontconfig.h>
#include <cairomm/cairomm.h>
@@ -39,21 +40,25 @@ DCPOMATIC_ENABLE_WARNINGS
#include <boost/algorithm/string.hpp>
#include <iostream>
-using std::list;
+
+using std::cerr;
using std::cout;
-using std::string;
-using std::min;
+using std::list;
+using std::make_pair;
+using std::make_shared;
using std::max;
+using std::min;
using std::pair;
-using std::cerr;
-using std::make_pair;
using std::shared_ptr;
+using std::string;
using boost::optional;
using boost::algorithm::replace_all;
using namespace dcpomatic;
-static FcConfig* fc_config = 0;
-static list<pair<boost::filesystem::path, string> > fc_config_fonts;
+
+static FcConfig* fc_config = nullptr;
+static list<pair<boost::filesystem::path, string>> fc_config_fonts;
+
string
marked_up (list<StringText> subtitles, int target_height, float fade_factor)
@@ -86,6 +91,7 @@ marked_up (list<StringText> subtitles, int target_height, float fade_factor)
return out;
}
+
static void
set_source_rgba (Cairo::RefPtr<Cairo::Context> context, dcp::Colour colour, float fade_factor)
{
@@ -97,7 +103,7 @@ static shared_ptr<Image>
create_image (dcp::Size size)
{
/* FFmpeg BGRA means first byte blue, second byte green, third byte red, fourth byte alpha */
- shared_ptr<Image> image (new Image(AV_PIX_FMT_BGRA, size, false));
+ auto image = make_shared<Image>(AV_PIX_FMT_BGRA, size, false);
image->make_black ();
return image;
}
@@ -107,7 +113,7 @@ static Cairo::RefPtr<Cairo::ImageSurface>
create_surface (shared_ptr<Image> image)
{
#ifdef DCPOMATIC_HAVE_FORMAT_STRIDE_FOR_WIDTH
- Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
+ auto surface = Cairo::ImageSurface::create (
image->data()[0],
Cairo::FORMAT_ARGB32,
image->size().width,
@@ -119,7 +125,7 @@ create_surface (shared_ptr<Image> image)
/* Centos 5 does not have Cairo::ImageSurface::format_stride_for_width, so just use width * 4
which I hope is safe (if slow)
*/
- Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
+ auto surface = Cairo::ImageSurface::create (
image->data()[0],
Cairo::FORMAT_ARGB32,
image->size().width,
@@ -133,22 +139,22 @@ create_surface (shared_ptr<Image> image)
static string
-setup_font (StringText const& subtitle, list<shared_ptr<Font> > const& fonts)
+setup_font (StringText const& subtitle, list<shared_ptr<Font>> const& fonts)
{
if (!fc_config) {
fc_config = FcInitLoadConfig ();
}
- optional<boost::filesystem::path> font_file = default_font_file ();
+ auto font_file = default_font_file ();
for (auto i: fonts) {
if (i->id() == subtitle.font() && i->file()) {
- font_file = i->file ();
+ font_file = i->file().get();
}
}
- list<pair<boost::filesystem::path, string> >::const_iterator existing = fc_config_fonts.begin ();
- while (existing != fc_config_fonts.end() && existing->first != *font_file) {
+ auto existing = fc_config_fonts.cbegin ();
+ while (existing != fc_config_fonts.end() && existing->first != font_file) {
++existing;
}
@@ -157,12 +163,12 @@ setup_font (StringText const& subtitle, list<shared_ptr<Font> > const& fonts)
font_name = existing->second;
} else {
/* Make this font available to DCP-o-matic */
- FcConfigAppFontAddFile (fc_config, reinterpret_cast<FcChar8 const *>(font_file->string().c_str()));
- FcPattern* pattern = FcPatternBuild (
- 0, FC_FILE, FcTypeString, font_file->string().c_str(), static_cast<char *> (0)
+ FcConfigAppFontAddFile (fc_config, reinterpret_cast<FcChar8 const *>(font_file.string().c_str()));
+ auto pattern = FcPatternBuild (
+ 0, FC_FILE, FcTypeString, font_file.string().c_str(), static_cast<char *>(0)
);
- FcObjectSet* object_set = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_LANG, FC_FILE, static_cast<char *> (0));
- FcFontSet* font_set = FcFontList (fc_config, pattern, object_set);
+ auto object_set = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_LANG, FC_FILE, static_cast<char *> (0));
+ auto font_set = FcFontList (fc_config, pattern, object_set);
if (font_set) {
for (int i = 0; i < font_set->nfont; ++i) {
FcPattern* font = font_set->fonts[i];
@@ -184,7 +190,7 @@ setup_font (StringText const& subtitle, list<shared_ptr<Font> > const& fonts)
FcObjectSetDestroy (object_set);
FcPatternDestroy (pattern);
- fc_config_fonts.push_back (make_pair(*font_file, font_name));
+ fc_config_fonts.push_back (make_pair(font_file, font_name));
}
FcConfigSetCurrent (fc_config);
@@ -200,10 +206,10 @@ calculate_fade_factor (StringText const& first, DCPTime time, int frame_rate)
/* Round the fade start/end to the nearest frame start. Otherwise if a subtitle starts just after
the start of a frame it will be faded out.
*/
- DCPTime const fade_in_start = DCPTime::from_seconds(first.in().as_seconds()).round(frame_rate);
- DCPTime const fade_in_end = fade_in_start + DCPTime::from_seconds (first.fade_up_time().as_seconds ());
- DCPTime const fade_out_end = DCPTime::from_seconds (first.out().as_seconds()).round(frame_rate);
- DCPTime const fade_out_start = fade_out_end - DCPTime::from_seconds (first.fade_down_time().as_seconds ());
+ auto const fade_in_start = DCPTime::from_seconds(first.in().as_seconds()).round(frame_rate);
+ auto const fade_in_end = fade_in_start + DCPTime::from_seconds (first.fade_up_time().as_seconds ());
+ auto const fade_out_end = DCPTime::from_seconds (first.out().as_seconds()).round(frame_rate);
+ auto const fade_out_start = fade_out_end - DCPTime::from_seconds (first.fade_down_time().as_seconds ());
if (fade_in_start <= time && time <= fade_in_end && fade_in_start != fade_in_end) {
fade_factor *= DCPTime(time - fade_in_start).seconds() / DCPTime(fade_in_end - fade_in_start).seconds();
@@ -223,7 +229,7 @@ static int
x_position (StringText const& first, int target_width, int layout_width)
{
int x = 0;
- switch (first.h_align ()) {
+ switch (first.h_align()) {
case dcp::HAlign::LEFT:
/* h_position is distance between left of frame and left of subtitle */
x = first.h_position() * target_width;
@@ -242,12 +248,11 @@ x_position (StringText const& first, int target_width, int layout_width)
}
-
static int
y_position (StringText const& first, int target_height, int layout_height)
{
int y = 0;
- switch (first.v_align ()) {
+ switch (first.v_align()) {
case dcp::VAlign::TOP:
/* SMPTE says that v_position is the distance between top
of frame and top of subtitle, but this doesn't always seem to be
@@ -280,6 +285,7 @@ setup_layout (Glib::RefPtr<Pango::Layout> layout, string font_name, string marku
layout->set_markup (markup);
}
+
/** Create a Pango layout using a dummy context which we can use to calculate the size
* of the text we will render. Then we can transfer the layout over to the real context
* for the actual render.
@@ -287,12 +293,12 @@ setup_layout (Glib::RefPtr<Pango::Layout> layout, string font_name, string marku
static Glib::RefPtr<Pango::Layout>
create_layout()
{
- PangoFontMap* c_font_map = pango_cairo_font_map_new ();
+ auto c_font_map = pango_cairo_font_map_new ();
DCPOMATIC_ASSERT (c_font_map);
- Glib::RefPtr<Pango::FontMap> font_map = Glib::wrap (c_font_map);
- PangoContext* c_context = pango_font_map_create_context (c_font_map);
+ auto font_map = Glib::wrap (c_font_map);
+ auto c_context = pango_font_map_create_context (c_font_map);
DCPOMATIC_ASSERT (c_context);
- Glib::RefPtr<Pango::Context> context = Glib::wrap (c_context);
+ auto context = Glib::wrap (c_context);
return Pango::Layout::create (context);
}
@@ -301,19 +307,19 @@ create_layout()
* at the same time and with the same fade in/out.
*/
static PositionImage
-render_line (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate)
+render_line (list<StringText> subtitles, list<shared_ptr<Font>> fonts, dcp::Size target, DCPTime time, int frame_rate)
{
/* XXX: this method can only handle italic / bold changes mid-line,
nothing else yet.
*/
DCPOMATIC_ASSERT (!subtitles.empty ());
- StringText const& first = subtitles.front ();
+ auto const& first = subtitles.front ();
- string const font_name = setup_font (first, fonts);
- float const fade_factor = calculate_fade_factor (first, time, frame_rate);
- string const markup = marked_up (subtitles, target.height, fade_factor);
- Glib::RefPtr<Pango::Layout> layout = create_layout ();
+ auto const font_name = setup_font (first, fonts);
+ auto const fade_factor = calculate_fade_factor (first, time, frame_rate);
+ auto const markup = marked_up (subtitles, target.height, fade_factor);
+ auto layout = create_layout ();
setup_layout (layout, font_name, markup);
dcp::Size size;
layout->get_pixel_size (size.width, size.height);
@@ -333,7 +339,7 @@ render_line (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Siz
}
}
- float const border_width = first.effect() == dcp::Effect::BORDER ? (first.outline_width * target.width / 2048.0) : 0;
+ auto const border_width = first.effect() == dcp::Effect::BORDER ? (first.outline_width * target.width / 2048.0) : 0;
size.width += 2 * ceil (border_width);
size.height += 2 * ceil (border_width);
@@ -348,9 +354,9 @@ render_line (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Siz
size.width += x_offset;
size.height += y_offset;
- shared_ptr<Image> image = create_image (size);
- Cairo::RefPtr<Cairo::Surface> surface = create_surface (image);
- Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (surface);
+ auto image = create_image (size);
+ auto surface = create_surface (image);
+ auto context = Cairo::Context::create (surface);
context->set_line_width (1);
context->scale (x_scale, y_scale);
@@ -398,7 +404,7 @@ render_line (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Siz
* @param frame_rate DCP frame rate.
*/
list<PositionImage>
-render_text (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate)
+render_text (list<StringText> subtitles, list<shared_ptr<Font>> fonts, dcp::Size target, DCPTime time, int frame_rate)
{
list<StringText> pending;
list<PositionImage> images;
@@ -411,7 +417,7 @@ render_text (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Siz
pending.push_back (i);
}
- if (!pending.empty ()) {
+ if (!pending.empty()) {
images.push_back (render_line (pending, fonts, target, time, frame_rate));
}
diff --git a/src/lib/send_kdm_email_job.cc b/src/lib/send_kdm_email_job.cc
index 8ed08f2a3..67ddd0eef 100644
--- a/src/lib/send_kdm_email_job.cc
+++ b/src/lib/send_kdm_email_job.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "send_kdm_email_job.h"
#include "compose.hpp"
#include "kdm_with_metadata.h"
@@ -26,11 +27,13 @@
#include "i18n.h"
+
using std::string;
using std::list;
using std::shared_ptr;
using boost::optional;
+
SendKDMEmailJob::SendKDMEmailJob (
list<KDMWithMetadataPtr> kdms,
dcp::NameFormat container_name_format,
@@ -49,6 +52,7 @@ SendKDMEmailJob::SendKDMEmailJob (
}
}
+
/** @param kdms KDMs to email.
* @param container_name_format Format to ues for folders / ZIP files.
* @param filename_format Format to use for filenames.
@@ -70,15 +74,17 @@ SendKDMEmailJob::SendKDMEmailJob (
}
+
SendKDMEmailJob::~SendKDMEmailJob ()
{
stop_thread ();
}
+
string
SendKDMEmailJob::name () const
{
- optional<string> f = _kdms.front().front()->get('f');
+ auto f = _kdms.front().front()->get('f');
if (!f || f->empty()) {
return _("Email KDMs");
}
@@ -86,12 +92,14 @@ SendKDMEmailJob::name () const
return String::compose (_("Email KDMs for %2"), *f);
}
+
string
SendKDMEmailJob::json_name () const
{
return N_("send_kdm_email");
}
+
void
SendKDMEmailJob::run ()
{
diff --git a/src/lib/send_kdm_email_job.h b/src/lib/send_kdm_email_job.h
index fa409edaa..2b010665c 100644
--- a/src/lib/send_kdm_email_job.h
+++ b/src/lib/send_kdm_email_job.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,18 +18,22 @@
*/
+
#include "job.h"
#include "kdm_with_metadata.h"
#include <dcp/types.h>
#include <dcp/name_format.h>
#include <boost/filesystem.hpp>
+
namespace dcpomatic {
class Screen;
}
+
class Log;
+
class SendKDMEmailJob : public Job
{
public:
@@ -41,7 +45,7 @@ public:
);
SendKDMEmailJob (
- std::list<std::list<KDMWithMetadataPtr> > kdms,
+ std::list<std::list<KDMWithMetadataPtr>> kdms,
dcp::NameFormat container_name_format,
dcp::NameFormat filename_format,
std::string cpl_name
@@ -57,5 +61,5 @@ private:
dcp::NameFormat _container_name_format;
dcp::NameFormat _filename_format;
std::string _cpl_name;
- std::list<std::list<KDMWithMetadataPtr> > _kdms;
+ std::list<std::list<KDMWithMetadataPtr>> _kdms;
};
diff --git a/src/lib/subtitle_analysis.cc b/src/lib/subtitle_analysis.cc
index 49041151f..0838816b0 100644
--- a/src/lib/subtitle_analysis.cc
+++ b/src/lib/subtitle_analysis.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "subtitle_analysis.h"
#include "exceptions.h"
#include "warnings.h"
@@ -27,9 +28,12 @@ DCPOMATIC_DISABLE_WARNINGS
#include <libxml++/libxml++.h>
DCPOMATIC_ENABLE_WARNINGS
+
+using std::make_shared;
+using std::shared_ptr;
using std::string;
using dcp::raw_convert;
-using std::shared_ptr;
+
int const SubtitleAnalysis::_current_state_version = 1;
@@ -62,13 +66,13 @@ SubtitleAnalysis::SubtitleAnalysis (boost::filesystem::path path)
void
SubtitleAnalysis::write (boost::filesystem::path path) const
{
- shared_ptr<xmlpp::Document> doc (new xmlpp::Document);
+ auto doc = make_shared<xmlpp::Document>();
xmlpp::Element* root = doc->create_root_node ("SubtitleAnalysis");
root->add_child("Version")->add_child_text (raw_convert<string>(_current_state_version));
if (_bounding_box) {
- xmlpp::Element* bounding_box = root->add_child("BoundingBox");
+ auto bounding_box = root->add_child("BoundingBox");
bounding_box->add_child("X")->add_child_text(raw_convert<string>(_bounding_box->x));
bounding_box->add_child("Y")->add_child_text(raw_convert<string>(_bounding_box->y));
bounding_box->add_child("Width")->add_child_text(raw_convert<string>(_bounding_box->width));
@@ -81,4 +85,3 @@ SubtitleAnalysis::write (boost::filesystem::path path) const
doc->write_to_file_formatted (path.string());
}
-
diff --git a/src/lib/subtitle_analysis.h b/src/lib/subtitle_analysis.h
index 6a7049a29..0a9dc6dca 100644
--- a/src/lib/subtitle_analysis.h
+++ b/src/lib/subtitle_analysis.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "rect.h"
#include <boost/noncopyable.hpp>
#include <boost/filesystem.hpp>
@@ -26,14 +27,13 @@
/** @class SubtitleAnalysis
* @brief Class to store the results of a SubtitleAnalysisJob.
*/
-
class SubtitleAnalysis : public boost::noncopyable
{
public:
explicit SubtitleAnalysis (boost::filesystem::path path);
SubtitleAnalysis (
- boost::optional<dcpomatic::Rect<double> > bounding_box,
+ boost::optional<dcpomatic::Rect<double>> bounding_box,
double analysis_x_offset_,
double analysis_y_offset_
)
@@ -44,7 +44,7 @@ public:
void write (boost::filesystem::path path) const;
- boost::optional<dcpomatic::Rect<double> > bounding_box () const {
+ boost::optional<dcpomatic::Rect<double>> bounding_box () const {
return _bounding_box;
}
@@ -61,7 +61,7 @@ private:
* expressed as a proportion of screen size (i.e. 0 is left hand side/top,
* 1 is right hand side/bottom), or empty if no subtitles were found.
*/
- boost::optional<dcpomatic::Rect<double> > _bounding_box;
+ boost::optional<dcpomatic::Rect<double>> _bounding_box;
double _analysis_x_offset;
double _analysis_y_offset;
diff --git a/src/lib/timer.cc b/src/lib/timer.cc
index 84329a5d5..caef89e0e 100644
--- a/src/lib/timer.cc
+++ b/src/lib/timer.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,21 +18,29 @@
*/
+
/** @file src/timer.cc
* @brief Some timing classes for debugging and profiling.
*/
+
+#include "compose.hpp"
#include "timer.h"
#include "util.h"
-#include "compose.hpp"
-#include <iostream>
#include <sys/time.h>
+#include <iostream>
#include "i18n.h"
-using namespace std;
+
+using std::cout;
+using std::list;
+using std::max;
+using std::pair;
+using std::string;
using boost::optional;
+
/** @param n Name to use when giving output */
PeriodTimer::PeriodTimer (string n)
: _name (n)
@@ -40,6 +48,7 @@ PeriodTimer::PeriodTimer (string n)
gettimeofday (&_start, 0);
}
+
/** Destroy PeriodTimer and output the time elapsed since its construction */
PeriodTimer::~PeriodTimer ()
{
@@ -48,6 +57,7 @@ PeriodTimer::~PeriodTimer ()
cout << N_("T: ") << _name << N_(": ") << (seconds (stop) - seconds (_start)) << N_("\n");
}
+
StateTimer::StateTimer (string n, string s)
: _name (n)
{
@@ -57,18 +67,21 @@ StateTimer::StateTimer (string n, string s)
_state = s;
}
+
StateTimer::StateTimer (string n)
: _name (n)
{
}
+
void
StateTimer::set (string s)
{
set_internal (s);
}
+
void
StateTimer::set_internal (optional<string> s)
{
@@ -88,16 +101,13 @@ StateTimer::set_internal (optional<string> s)
_state = s;
}
+
void
StateTimer::unset ()
{
set_internal (optional<string>());
}
-bool compare (pair<double, string> a, pair<double, string> b)
-{
- return a.first > b.first;
-}
/** Destroy StateTimer and generate a summary of the state timings on cout */
StateTimer::~StateTimer ()
@@ -113,7 +123,7 @@ StateTimer::~StateTimer ()
longest = max (longest, int(i.first.length()));
}
- list<pair<double, string> > sorted;
+ list<pair<double, string>> sorted;
for (auto const& i: _counts) {
string name = i.first + string(longest + 1 - i.first.size(), ' ');
@@ -123,7 +133,10 @@ StateTimer::~StateTimer ()
sorted.push_back (make_pair(i.second.total_time, String::compose("\t%1%2 %3 %4", name, total_time, i.second.number, (i.second.total_time / i.second.number))));
}
- sorted.sort (compare);
+ sorted.sort ([](pair<double, string> const& a, pair<double, string> const& b) {
+ return a.first > b.first;
+ });
+
cout << _name << N_(":\n");
for (auto const& i: sorted) {
diff --git a/src/lib/timer.h b/src/lib/timer.h
index e18b799d9..6435155c6 100644
--- a/src/lib/timer.h
+++ b/src/lib/timer.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,18 +18,22 @@
*/
+
/** @file src/timer.h
* @brief Some timing classes for debugging and profiling.
*/
+
#ifndef DCPOMATIC_TIMER_H
#define DCPOMATIC_TIMER_H
+
#include <sys/time.h>
#include <boost/optional.hpp>
#include <string>
#include <map>
+
/** @class PeriodTimer
* @brief A class to allow timing of a period within the caller.
*
diff --git a/src/lib/video_content.h b/src/lib/video_content.h
index 4e9e5815f..c1e1dbeec 100644
--- a/src/lib/video_content.h
+++ b/src/lib/video_content.h
@@ -61,7 +61,7 @@ class VideoContent : public ContentPart, public std::enable_shared_from_this<Vid
public:
explicit VideoContent (Content* parent);
VideoContent (Content* parent, cxml::ConstNodePtr, int);
- VideoContent (Content* parent, std::vector<std::shared_ptr<Content> >);
+ VideoContent (Content* parent, std::vector<std::shared_ptr<Content>>);
void as_xml (xmlpp::Node *) const;
std::string technical_summary () const;
@@ -249,4 +249,5 @@ private:
boost::optional<dcp::LanguageTag> _burnt_subtitle_language;
};
+
#endif
diff --git a/src/lib/zipper.cc b/src/lib/zipper.cc
index 005e15248..2c334dc94 100644
--- a/src/lib/zipper.cc
+++ b/src/lib/zipper.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,6 +18,7 @@
*/
+
#include "zipper.h"
#include "exceptions.h"
#include "dcpomatic_assert.h"
@@ -25,6 +26,7 @@
#include <boost/filesystem.hpp>
#include <stdexcept>
+
using std::string;
using std::runtime_error;
using std::shared_ptr;
@@ -49,7 +51,7 @@ Zipper::add (string name, string content)
shared_ptr<string> copy(new string(content));
_store.push_back (copy);
- struct zip_source* source = zip_source_buffer (_zip, copy->c_str(), copy->length(), 0);
+ auto source = zip_source_buffer (_zip, copy->c_str(), copy->length(), 0);
if (!source) {
throw runtime_error ("could not create ZIP source");
}
diff --git a/src/lib/zipper.h b/src/lib/zipper.h
index c2b40556c..62a6af5b9 100644
--- a/src/lib/zipper.h
+++ b/src/lib/zipper.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,10 +18,12 @@
*/
+
#include <boost/noncopyable.hpp>
#include <boost/filesystem.hpp>
#include <vector>
+
class Zipper : public boost::noncopyable
{
public:
@@ -33,6 +35,6 @@ public:
private:
struct zip* _zip;
- std::vector<std::shared_ptr<std::string> > _store;
+ std::vector<std::shared_ptr<std::string>> _store;
};