summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-01-11 16:46:13 +0100
committerCarl Hetherington <cth@carlh.net>2021-01-11 16:46:13 +0100
commit9b946fc5250eff5a5dd4a661896916fcd5d9bd4b (patch)
tree2626cce11334b2019bda77087e8ac4496afd61da /src/lib
parent0241df1707c7ea5658f471828ff6dc944e21af42 (diff)
More c++ tidying.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcp_encoder.cc15
-rw-r--r--src/lib/encode_server.cc31
-rw-r--r--src/lib/film.cc172
-rw-r--r--src/lib/film.h3
-rw-r--r--src/lib/j2k_encoder.cc41
-rw-r--r--src/lib/util.cc37
6 files changed, 147 insertions, 152 deletions
diff --git a/src/lib/dcp_encoder.cc b/src/lib/dcp_encoder.cc
index 0478fcf80..4b4785cc6 100644
--- a/src/lib/dcp_encoder.cc
+++ b/src/lib/dcp_encoder.cc
@@ -49,6 +49,7 @@ using std::vector;
using std::shared_ptr;
using std::weak_ptr;
using std::dynamic_pointer_cast;
+using std::make_shared;
using boost::optional;
#if BOOST_VERSION >= 106100
using namespace boost::placeholders;
@@ -90,26 +91,26 @@ DCPEncoder::~DCPEncoder ()
void
DCPEncoder::go ()
{
- _writer.reset (new Writer (_film, _job));
+ _writer = make_shared<Writer>(_film, _job);
_writer->start ();
- _j2k_encoder.reset (new J2KEncoder (_film, _writer));
+ _j2k_encoder = make_shared<J2KEncoder>(_film, _writer);
_j2k_encoder->begin ();
{
- shared_ptr<Job> job = _job.lock ();
+ auto job = _job.lock ();
DCPOMATIC_ASSERT (job);
job->sub (_("Encoding"));
}
if (_non_burnt_subtitles) {
- vector<FontData> fonts = _player->get_subtitle_fonts ();
+ auto fonts = _player->get_subtitle_fonts ();
if (fonts.size() > 1 && _film->interop()) {
/* Interop will ignore second and subsequent <LoadFont>s so don't even
write them as they upset some validators.
*/
- FontData first = fonts.front ();
+ auto first = fonts.front();
fonts.clear ();
fonts.push_back (first);
}
@@ -149,7 +150,7 @@ DCPEncoder::audio (shared_ptr<AudioBuffers> data, DCPTime time)
{
_writer->write (data, time);
- shared_ptr<Job> job = _job.lock ();
+ auto job = _job.lock ();
DCPOMATIC_ASSERT (job);
job->set_progress (float(time.get()) / _film->length().get());
}
@@ -174,7 +175,7 @@ optional<float>
DCPEncoder::current_rate () const
{
if (!_j2k_encoder) {
- return optional<float>();
+ return {};
}
return _j2k_encoder->current_encoding_rate ();
diff --git a/src/lib/encode_server.cc b/src/lib/encode_server.cc
index 6ec3e701c..92589c573 100644
--- a/src/lib/encode_server.cc
+++ b/src/lib/encode_server.cc
@@ -60,6 +60,7 @@ using std::cout;
using std::cerr;
using std::fixed;
using std::shared_ptr;
+using std::make_shared;
using boost::thread;
using boost::bind;
using boost::scoped_array;
@@ -123,7 +124,7 @@ EncodeServer::process (shared_ptr<Socket> socket, struct timeval& after_read, st
socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
string s (buffer.get());
- shared_ptr<cxml::Document> xml (new cxml::Document ("EncodingRequest"));
+ auto xml = make_shared<cxml::Document>("EncodingRequest");
xml->read_string (s);
/* This is a double-check; the server shouldn't even be on the candidate list
if it is the wrong version, but it doesn't hurt to make sure here.
@@ -134,7 +135,7 @@ EncodeServer::process (shared_ptr<Socket> socket, struct timeval& after_read, st
return -1;
}
- shared_ptr<PlayerVideo> pvf (new PlayerVideo (xml, socket));
+ auto pvf = make_shared<PlayerVideo>(xml, socket);
if (!ds.check()) {
throw NetworkError ("Checksums do not match");
@@ -144,7 +145,7 @@ EncodeServer::process (shared_ptr<Socket> socket, struct timeval& after_read, st
gettimeofday (&after_read, 0);
- ArrayData encoded = dcp_video_frame.encode_locally ();
+ auto encoded = dcp_video_frame.encode_locally ();
gettimeofday (&after_encode, 0);
@@ -174,7 +175,7 @@ EncodeServer::worker_thread ()
return;
}
- shared_ptr<Socket> socket = _queue.front ();
+ auto socket = _queue.front ();
_queue.pop_front ();
lock.unlock ();
@@ -207,13 +208,11 @@ EncodeServer::worker_thread ()
struct timeval end;
gettimeofday (&end, 0);
- shared_ptr<EncodedLogEntry> e (
- new EncodedLogEntry (
- frame, ip,
- seconds(after_read) - seconds(start),
- seconds(after_encode) - seconds(after_read),
- seconds(end) - seconds(after_encode)
- )
+ auto e = make_shared<EncodedLogEntry>(
+ frame, ip,
+ seconds(after_read) - seconds(start),
+ seconds(after_encode) - seconds(after_read),
+ seconds(end) - seconds(after_encode)
);
if (_verbose) {
@@ -256,7 +255,7 @@ void
EncodeServer::broadcast_thread ()
try
{
- boost::asio::ip::address address = boost::asio::ip::address_v4::any ();
+ auto address = boost::asio::ip::address_v4::any ();
boost::asio::ip::udp::endpoint listen_endpoint (address, HELLO_PORT);
_broadcast.socket = new boost::asio::ip::udp::socket (_broadcast.io_service);
@@ -284,17 +283,17 @@ EncodeServer::broadcast_received ()
if (strcmp (_broadcast.buffer, DCPOMATIC_HELLO) == 0) {
/* Reply to the client saying what we can do */
xmlpp::Document doc;
- xmlpp::Element* root = doc.create_root_node ("ServerAvailable");
+ auto root = doc.create_root_node ("ServerAvailable");
root->add_child("Threads")->add_child_text (raw_convert<string> (_worker_threads.size ()));
root->add_child("Version")->add_child_text (raw_convert<string> (SERVER_LINK_VERSION));
- string xml = doc.write_to_string ("UTF-8");
+ auto xml = doc.write_to_string ("UTF-8");
if (_verbose) {
cout << "Offering services to master " << _broadcast.send_endpoint.address().to_string () << "\n";
}
try {
- shared_ptr<Socket> socket (new Socket);
+ auto socket = make_shared<Socket>();
socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), MAIN_SERVER_PRESENCE_PORT));
socket->write (xml.length() + 1);
socket->write ((uint8_t *) xml.c_str(), xml.length() + 1);
@@ -303,7 +302,7 @@ EncodeServer::broadcast_received ()
}
try {
- shared_ptr<Socket> socket (new Socket);
+ auto socket = make_shared<Socket>();
socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), BATCH_SERVER_PRESENCE_PORT));
socket->write (xml.length() + 1);
socket->write ((uint8_t *) xml.c_str(), xml.length() + 1);
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 8bcbaebe5..a0f25d84b 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.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.
@@ -98,6 +98,7 @@ using std::exception;
using std::find;
using std::shared_ptr;
using std::weak_ptr;
+using std::make_shared;
using std::dynamic_pointer_cast;
using boost::optional;
using boost::is_any_of;
@@ -192,16 +193,16 @@ Film::Film (optional<boost::filesystem::path> dir)
boost::filesystem::path p (boost::filesystem::system_complete (dir.get()));
boost::filesystem::path result;
- for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
- if (*i == "..") {
+ for (auto i: p) {
+ if (i == "..") {
boost::system::error_code ec;
if (boost::filesystem::is_symlink(result, ec) || result.filename() == "..") {
- result /= *i;
+ result /= i;
} else {
result = result.parent_path ();
}
- } else if (*i != ".") {
- result /= *i;
+ } else if (i != ".") {
+ result /= i;
}
}
@@ -209,9 +210,9 @@ Film::Film (optional<boost::filesystem::path> dir)
}
if (_directory) {
- _log.reset (new FileLog (file ("log")));
+ _log = make_shared<FileLog>(file("log"));
} else {
- _log.reset (new NullLog);
+ _log = make_shared<NullLog>();
}
_playlist->set_sequence (_sequence);
@@ -284,7 +285,7 @@ Film::internal_video_asset_filename (DCPTimePeriod p) const
boost::filesystem::path
Film::audio_analysis_path (shared_ptr<const Playlist> playlist) const
{
- boost::filesystem::path p = dir ("analysis");
+ auto p = dir ("analysis");
Digester digester;
for (auto i: playlist->content ()) {
@@ -319,13 +320,13 @@ Film::audio_analysis_path (shared_ptr<const Playlist> playlist) const
boost::filesystem::path
Film::subtitle_analysis_path (shared_ptr<const Content> content) const
{
- boost::filesystem::path p = dir ("analysis");
+ auto p = dir ("analysis");
Digester digester;
digester.add (content->digest());
if (!content->text.empty()) {
- shared_ptr<TextContent> tc = content->text.front();
+ auto tc = content->text.front();
digester.add (tc->x_scale());
digester.add (tc->y_scale());
for (auto i: tc->fonts()) {
@@ -338,7 +339,7 @@ Film::subtitle_analysis_path (shared_ptr<const Content> content) const
digester.add (tc->outline_width());
}
- shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent>(content);
+ auto fc = dynamic_pointer_cast<const FFmpegContent>(content);
if (fc) {
digester.add (fc->subtitle_stream()->identifier());
}
@@ -359,7 +360,7 @@ Film::make_dcp (bool gui, bool check)
throw BadSettingError (_("name"), _("Cannot contain slashes"));
}
- if (container() == 0) {
+ if (container() == nullptr) {
throw MissingSettingError (_("container"));
}
@@ -371,7 +372,7 @@ Film::make_dcp (bool gui, bool check)
throw runtime_error (_("The DCP is empty, perhaps because all the content has zero length."));
}
- if (dcp_content_type() == 0) {
+ if (dcp_content_type() == nullptr) {
throw MissingSettingError (_("content type"));
}
@@ -383,7 +384,7 @@ Film::make_dcp (bool gui, bool check)
if (!i->paths_valid()) {
throw runtime_error (_("some of your content is missing"));
}
- shared_ptr<const DCPContent> dcp = dynamic_pointer_cast<const DCPContent> (i);
+ auto dcp = dynamic_pointer_cast<const DCPContent>(i);
if (dcp && dcp->needs_kdm()) {
throw runtime_error (_("Some of your content needs a KDM"));
}
@@ -409,10 +410,10 @@ Film::make_dcp (bool gui, bool check)
}
LOG_GENERAL ("J2K bandwidth %1", j2k_bandwidth());
- shared_ptr<TranscodeJob> tj (new TranscodeJob (shared_from_this()));
- tj->set_encoder (shared_ptr<Encoder> (new DCPEncoder (shared_from_this(), tj)));
+ auto tj = make_shared<TranscodeJob>(shared_from_this());
+ tj->set_encoder (make_shared<DCPEncoder>(shared_from_this(), tj));
if (check) {
- shared_ptr<CheckContentChangeJob> cc (new CheckContentChangeJob(shared_from_this(), tj, gui));
+ auto cc = make_shared<CheckContentChangeJob>(shared_from_this(), tj, gui);
JobManager::instance()->add (cc);
} else {
JobManager::instance()->add (tj);
@@ -423,15 +424,14 @@ Film::make_dcp (bool gui, bool check)
void
Film::send_dcp_to_tms ()
{
- shared_ptr<Job> j (new UploadJob (shared_from_this()));
- JobManager::instance()->add (j);
+ JobManager::instance()->add(make_shared<UploadJob>(shared_from_this()));
}
shared_ptr<xmlpp::Document>
Film::metadata (bool with_content_paths) const
{
- shared_ptr<xmlpp::Document> doc (new xmlpp::Document);
- xmlpp::Element* root = doc->create_root_node ("Metadata");
+ auto doc = make_shared<xmlpp::Document>();
+ auto root = doc->create_root_node ("Metadata");
root->add_child("Version")->add_child_text (raw_convert<string> (current_state_version));
root->add_child("Name")->add_child_text (_name);
@@ -465,7 +465,7 @@ Film::metadata (bool with_content_paths) const
root->add_child("ReencodeJ2K")->add_child_text (_reencode_j2k ? "1" : "0");
root->add_child("UserExplicitVideoFrameRate")->add_child_text(_user_explicit_video_frame_rate ? "1" : "0");
for (map<dcp::Marker, DCPTime>::const_iterator i = _markers.begin(); i != _markers.end(); ++i) {
- xmlpp::Element* m = root->add_child("Marker");
+ auto m = root->add_child("Marker");
m->set_attribute("Type", dcp::marker_to_string(i->first));
m->add_child_text(raw_convert<string>(i->second.get()));
}
@@ -498,8 +498,7 @@ Film::metadata (bool with_content_paths) const
void
Film::write_metadata (boost::filesystem::path path) const
{
- shared_ptr<xmlpp::Document> doc = metadata ();
- doc->write_to_file_formatted (path.string());
+ metadata()->write_to_file_formatted(path.string());
}
/** Write state to our `metadata' file */
@@ -508,8 +507,7 @@ Film::write_metadata () const
{
DCPOMATIC_ASSERT (directory());
boost::filesystem::create_directories (directory().get());
- shared_ptr<xmlpp::Document> doc = metadata ();
- doc->write_to_file_formatted (file(metadata_file).string ());
+ metadata()->write_to_file_formatted(file(metadata_file).string());
_dirty = false;
}
@@ -519,7 +517,7 @@ Film::write_template (boost::filesystem::path path) const
{
boost::filesystem::create_directories (path.parent_path());
shared_ptr<xmlpp::Document> doc = metadata (false);
- doc->write_to_file_formatted (path.string ());
+ metadata(false)->write_to_file_formatted(path.string());
}
/** Read state from our metadata file.
@@ -548,7 +546,7 @@ Film::read_metadata (optional<boost::filesystem::path> path)
throw runtime_error (_("This film was created with a newer version of DCP-o-matic, and it cannot be loaded into this version. Sorry!"));
} else if (_state_version < current_state_version) {
/* This is an older version; save a copy (if we haven't already) */
- boost::filesystem::path const older = path->parent_path() / String::compose("metadata.%1.xml", _state_version);
+ auto const older = path->parent_path() / String::compose("metadata.%1.xml", _state_version);
if (!boost::filesystem::is_regular_file(older)) {
try {
boost::filesystem::copy_file(*path, older);
@@ -571,14 +569,14 @@ Film::read_metadata (optional<boost::filesystem::path> path)
{
- optional<string> c = f.optional_string_child ("DCPContentType");
+ auto c = f.optional_string_child("DCPContentType");
if (c) {
_dcp_content_type = DCPContentType::from_isdcf_name (c.get ());
}
}
{
- optional<string> c = f.optional_string_child ("Container");
+ auto c = f.optional_string_child("Container");
if (c) {
_container = Ratio::from_id (c.get ());
}
@@ -616,7 +614,7 @@ Film::read_metadata (optional<boost::filesystem::path> path)
}
if (_audio_processor && !Config::instance()->show_experimental_audio_processors()) {
- list<AudioProcessor const *> ap = AudioProcessor::visible();
+ auto ap = AudioProcessor::visible();
if (find(ap.begin(), ap.end(), _audio_processor) == ap.end()) {
Config::instance()->set_show_experimental_audio_processors(true);
}
@@ -639,22 +637,22 @@ Film::read_metadata (optional<boost::filesystem::path> path)
_content_versions.push_back (i->content());
}
- optional<string> name_language = f.optional_string_child("NameLanguage");
+ auto name_language = f.optional_string_child("NameLanguage");
if (name_language) {
_name_language = dcp::LanguageTag (*name_language);
}
- optional<string> audio_language = f.optional_string_child("AudioLanguage");
+ auto audio_language = f.optional_string_child("AudioLanguage");
if (audio_language) {
_audio_language = dcp::LanguageTag (*audio_language);
}
- optional<string> release_territory = f.optional_string_child("ReleaseTerritory");
+ auto release_territory = f.optional_string_child("ReleaseTerritory");
if (release_territory) {
_release_territory = dcp::LanguageTag::RegionSubtag (*release_territory);
}
_version_number = f.optional_number_child<int>("VersionNumber").get_value_or(0);
- optional<string> status = f.optional_string_child("Status");
+ auto status = f.optional_string_child("Status");
if (status) {
_status = dcp::string_to_status (*status);
}
@@ -663,8 +661,8 @@ Film::read_metadata (optional<boost::filesystem::path> path)
_distributor = f.optional_string_child("Distributor").get_value_or("");
_facility = f.optional_string_child("Facility").get_value_or("");
- float value = f.optional_number_child<float>("LuminanceValue").get_value_or(4.5);
- optional<string> unit = f.optional_string_child("LuminanceUnit");
+ auto value = f.optional_number_child<float>("LuminanceValue").get_value_or(4.5);
+ auto unit = f.optional_string_child("LuminanceUnit");
if (unit) {
_luminance = dcp::Luminance (value, dcp::Luminance::string_to_unit(*unit));
}
@@ -693,7 +691,7 @@ Film::read_metadata (optional<boost::filesystem::path> path)
optional<dcp::LanguageTag> found_language;
for (auto i: f.node_child("Playlist")->node_children("Content")) {
- cxml::ConstNodePtr text = i->optional_node_child("Text");
+ auto text = i->optional_node_child("Text");
if (text && text->optional_string_child("Language") && !found_language) {
try {
found_language = dcp::LanguageTag(text->string_child("Language"));
@@ -702,7 +700,7 @@ Film::read_metadata (optional<boost::filesystem::path> path)
}
if (_state_version >= 9) {
- optional<string> isdcf_language = f.node_child("ISDCFMetadata")->optional_string_child("SubtitleLanguage");
+ auto isdcf_language = f.node_child("ISDCFMetadata")->optional_string_child("SubtitleLanguage");
if (isdcf_language && !found_language) {
try {
found_language = dcp::LanguageTag(*isdcf_language);
@@ -774,7 +772,7 @@ Film::mapped_audio_channels () const
} else {
for (auto i: content ()) {
if (i->audio) {
- list<int> c = i->audio->mapping().mapped_output_channels ();
+ auto c = i->audio->mapping().mapped_output_channels ();
copy (c.begin(), c.end(), back_inserter (mapped));
}
}
@@ -792,7 +790,7 @@ Film::isdcf_name (bool if_created_now) const
{
string d;
- string raw_name = name ();
+ auto raw_name = name ();
/* Split the raw name up into words */
vector<string> words;
@@ -801,16 +799,16 @@ Film::isdcf_name (bool if_created_now) const
string fixed_name;
/* Add each word to fixed_name */
- for (vector<string>::const_iterator i = words.begin(); i != words.end(); ++i) {
- string w = *i;
+ for (auto i: words) {
+ string w = i;
/* First letter is always capitalised */
w[0] = toupper (w[0]);
/* Count caps in w */
size_t caps = 0;
- for (size_t i = 0; i < w.size(); ++i) {
- if (isupper (w[i])) {
+ for (size_t j = 0; j < w.size(); ++j) {
+ if (isupper (w[j])) {
++caps;
}
}
@@ -819,13 +817,13 @@ Film::isdcf_name (bool if_created_now) const
leave it alone.
*/
if (caps == w.size ()) {
- for (size_t i = 1; i < w.size(); ++i) {
- w[i] = tolower (w[i]);
+ for (size_t j = 1; j < w.size(); ++j) {
+ w[j] = tolower (w[j]);
}
}
- for (size_t i = 0; i < w.size(); ++i) {
- fixed_name += w[i];
+ for (size_t j = 0; j < w.size(); ++j) {
+ fixed_name += w[j];
}
}
@@ -840,7 +838,7 @@ Film::isdcf_name (bool if_created_now) const
d += "-" + raw_convert<string>(isdcf_metadata().content_version);
}
- ISDCFMetadata const dm = isdcf_metadata ();
+ auto const dm = isdcf_metadata ();
if (dm.temp_version) {
d += "-Temp";
@@ -882,7 +880,7 @@ Film::isdcf_name (bool if_created_now) const
/* Interior aspect ratio. The standard says we don't do this for trailers, for some strange reason */
if (dcp_content_type() && dcp_content_type()->libdcp_kind() != dcp::TRAILER) {
- Ratio const * content_ratio = 0;
+ Ratio const* content_ratio = nullptr;
for (auto i: content ()) {
if (i->video) {
/* Here's the first piece of video content */
@@ -904,8 +902,8 @@ Film::isdcf_name (bool if_created_now) const
for now I'm just appending -CCAP if we have any closed captions.
*/
- bool burnt_in = true;
- bool ccap = false;
+ auto burnt_in = true;
+ auto ccap = false;
for (auto i: content()) {
for (auto j: i->text) {
if (j->type() == TEXT_OPEN_SUBTITLE && j->use() && !j->burn()) {
@@ -917,7 +915,7 @@ Film::isdcf_name (bool if_created_now) const
}
if (!_subtitle_languages.empty()) {
- string lang = _subtitle_languages.front().language().get_value_or("en").subtag();
+ auto lang = _subtitle_languages.front().language().get_value_or("en").subtag();
if (burnt_in) {
transform (lang.begin(), lang.end(), lang.begin(), ::tolower);
} else {
@@ -945,9 +943,9 @@ Film::isdcf_name (bool if_created_now) const
/* Count mapped audio channels */
- list<int> mapped = mapped_audio_channels ();
+ auto mapped = mapped_audio_channels ();
- pair<int, int> ch = audio_channel_types (mapped, audio_channels());
+ auto ch = audio_channel_types (mapped, audio_channels());
if (!ch.first && !ch.second) {
d += "_MOS";
} else if (ch.first) {
@@ -987,9 +985,9 @@ Film::isdcf_name (bool if_created_now) const
d += "-3D";
}
- bool vf = false;
+ auto vf = false;
for (auto i: content()) {
- shared_ptr<const DCPContent> dc = dynamic_pointer_cast<const DCPContent> (i);
+ auto dc = dynamic_pointer_cast<const DCPContent>(i);
if (!dc) {
continue;
}
@@ -1254,15 +1252,15 @@ Film::cpls () const
vector<CPLSummary> out;
- boost::filesystem::path const dir = directory().get();
- for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator(dir); i != boost::filesystem::directory_iterator(); ++i) {
+ auto const dir = directory().get();
+ for (auto i: boost::filesystem::directory_iterator(dir)) {
if (
- boost::filesystem::is_directory (*i) &&
- i->path().leaf() != "j2c" && i->path().leaf() != "video" && i->path().leaf() != "info" && i->path().leaf() != "analysis"
+ boost::filesystem::is_directory (i) &&
+ i.path().leaf() != "j2c" && i.path().leaf() != "video" && i.path().leaf() != "info" && i.path().leaf() != "analysis"
) {
try {
- out.push_back (CPLSummary(*i));
+ out.push_back (CPLSummary(i));
} catch (...) {
}
@@ -1297,7 +1295,7 @@ Film::examine_and_add_content (shared_ptr<Content> content, bool disable_audio_a
run_ffprobe (content->path(0), file("ffprobe.log"));
}
- shared_ptr<Job> j (new ExamineContentJob (shared_from_this(), content));
+ auto j = make_shared<ExamineContentJob>(shared_from_this(), content);
_job_connections.push_back (
j->Finished.connect (bind (&Film::maybe_add_content, this, weak_ptr<Job>(j), weak_ptr<Content>(content), disable_audio_analysis))
@@ -1309,12 +1307,12 @@ Film::examine_and_add_content (shared_ptr<Content> content, bool disable_audio_a
void
Film::maybe_add_content (weak_ptr<Job> j, weak_ptr<Content> c, bool disable_audio_analysis)
{
- shared_ptr<Job> job = j.lock ();
+ auto job = j.lock ();
if (!job || !job->finished_ok ()) {
return;
}
- shared_ptr<Content> content = c.lock ();
+ auto content = c.lock ();
if (!content) {
return;
}
@@ -1322,7 +1320,7 @@ Film::maybe_add_content (weak_ptr<Job> j, weak_ptr<Content> c, bool disable_audi
add_content (content);
if (Config::instance()->automatic_audio_analysis() && content->audio && !disable_audio_analysis) {
- shared_ptr<Playlist> playlist (new Playlist);
+ auto playlist = make_shared<Playlist>();
playlist->add (shared_from_this(), content);
boost::signals2::connection c;
JobManager::instance()->analyse_audio (
@@ -1429,7 +1427,7 @@ int
Film::best_video_frame_rate () const
{
/* Don't default to anything above 30fps (make the user select that explicitly) */
- int best = _playlist->best_video_frame_rate ();
+ auto best = _playlist->best_video_frame_rate ();
if (best > 30) {
best /= 2;
}
@@ -1505,7 +1503,7 @@ Film::check_settings_consistency ()
bool change_made = false;
for (auto i: content()) {
- shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
+ auto d = dynamic_pointer_cast<DCPContent>(i);
if (!d) {
continue;
}
@@ -1589,7 +1587,7 @@ Film::frame_size () const
dcp::Size
Film::active_area () const
{
- dcp::Size const frame = frame_size ();
+ auto const frame = frame_size ();
dcp::Size active;
for (auto i: content()) {
@@ -1630,8 +1628,8 @@ Film::make_kdm (
throw runtime_error (_("Cannot make a KDM as this project is not encrypted."));
}
- shared_ptr<const dcp::CPL> cpl (new dcp::CPL (cpl_file));
- shared_ptr<const dcp::CertificateChain> signer = Config::instance()->signer_chain ();
+ auto cpl = make_shared<dcp::CPL>(cpl_file);
+ auto signer = Config::instance()->signer_chain();
if (!signer->valid ()) {
throw InvalidSignerError ();
}
@@ -1639,10 +1637,10 @@ Film::make_kdm (
/* Find keys that have been added to imported, encrypted DCP content */
list<dcp::DecryptedKDMKey> imported_keys;
for (auto i: content()) {
- shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (i);
+ auto d = dynamic_pointer_cast<DCPContent> (i);
if (d && d->kdm()) {
dcp::DecryptedKDM kdm (d->kdm().get(), Config::instance()->decryption_chain()->key().get());
- list<dcp::DecryptedKDMKey> keys = kdm.keys ();
+ auto keys = kdm.keys ();
copy (keys.begin(), keys.end(), back_inserter (imported_keys));
}
}
@@ -1700,7 +1698,7 @@ Film::should_be_enough_disk_space (double& required, double& available, bool& ca
boost::filesystem::path test = internal_video_asset_dir() / "test";
boost::filesystem::path test2 = internal_video_asset_dir() / "test2";
can_hard_link = true;
- FILE* f = fopen_boost (test, "w");
+ auto f = fopen_boost (test, "w");
if (f) {
fclose (f);
boost::system::error_code ec;
@@ -1712,7 +1710,7 @@ Film::should_be_enough_disk_space (double& required, double& available, bool& ca
boost::filesystem::remove (test2);
}
- boost::filesystem::space_info s = boost::filesystem::space (internal_video_asset_dir ());
+ auto s = boost::filesystem::space (internal_video_asset_dir ());
required = double (required_disk_space ()) / 1073741824.0f;
if (!can_hard_link) {
required *= 2;
@@ -1766,7 +1764,7 @@ list<DCPTimePeriod>
Film::reels () const
{
list<DCPTimePeriod> p;
- DCPTime const len = length();
+ auto const len = length();
switch (reel_type ()) {
case REELTYPE_SINGLE:
@@ -1870,7 +1868,7 @@ bool
Film::references_dcp_video () const
{
for (auto i: _playlist->content()) {
- shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
+ auto d = dynamic_pointer_cast<DCPContent>(i);
if (d && d->reference_video()) {
return true;
}
@@ -1883,7 +1881,7 @@ bool
Film::references_dcp_audio () const
{
for (auto i: _playlist->content()) {
- shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
+ auto d = dynamic_pointer_cast<DCPContent>(i);
if (d && d->reference_audio()) {
return true;
}
@@ -1913,7 +1911,7 @@ Film::closed_caption_tracks () const
for (auto i: content()) {
for (auto j: i->text) {
/* XXX: Empty DCPTextTrack ends up being a magic value here - the "unknown" or "not specified" track */
- DCPTextTrack dtt = j->dcp_track().get_value_or(DCPTextTrack());
+ auto dtt = j->dcp_track().get_value_or(DCPTextTrack());
if (j->type() == TEXT_CLOSED_CAPTION && find(tt.begin(), tt.end(), dtt) == tt.end()) {
tt.push_back (dtt);
}
@@ -2028,9 +2026,7 @@ Film::set_luminance (dcp::Luminance l)
void
Film::set_subtitle_language (dcp::LanguageTag language)
{
- vector<dcp::LanguageTag> lang;
- lang.push_back (language);
- set_subtitle_languages (lang);
+ set_subtitle_languages ({language});
}
@@ -2061,9 +2057,9 @@ Film::set_facility (string f)
optional<DCPTime>
Film::marker (dcp::Marker type) const
{
- map<dcp::Marker, DCPTime>::const_iterator i = _markers.find (type);
+ auto i = _markers.find (type);
if (i == _markers.end()) {
- return optional<DCPTime>();
+ return {};
}
return i->second;
}
@@ -2071,7 +2067,7 @@ Film::marker (dcp::Marker type) const
shared_ptr<InfoFileHandle>
Film::info_file_handle (DCPTimePeriod period, bool read) const
{
- return shared_ptr<InfoFileHandle> (new InfoFileHandle(_info_file_mutex, info_file(period), read));
+ return std::make_shared<InfoFileHandle>(_info_file_mutex, info_file(period), read);
}
InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read)
@@ -2084,7 +2080,7 @@ InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path fil
throw OpenFileError (file, errno, OpenFileError::READ);
}
} else {
- bool const exists = boost::filesystem::exists (file);
+ auto const exists = boost::filesystem::exists (file);
if (exists) {
_handle = fopen_boost (file, "r+b");
} else {
diff --git a/src/lib/film.h b/src/lib/film.h
index d79448689..6828df21a 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -67,6 +67,7 @@ struct atmos_encrypted_passthrough_test;
class InfoFileHandle
{
public:
+ InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read);
~InfoFileHandle ();
FILE* get () const {
@@ -80,8 +81,6 @@ public:
private:
friend class Film;
- InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read);
-
boost::mutex::scoped_lock _lock;
FILE* _handle;
boost::filesystem::path _file;
diff --git a/src/lib/j2k_encoder.cc b/src/lib/j2k_encoder.cc
index acd27932e..7c6e23477 100644
--- a/src/lib/j2k_encoder.cc
+++ b/src/lib/j2k_encoder.cc
@@ -46,6 +46,7 @@ using std::cout;
using std::exception;
using std::shared_ptr;
using std::weak_ptr;
+using std::make_shared;
using boost::optional;
using dcp::Data;
using namespace dcpomatic;
@@ -83,7 +84,7 @@ J2KEncoder::begin ()
void
J2KEncoder::call_servers_list_changed (weak_ptr<J2KEncoder> encoder)
{
- shared_ptr<J2KEncoder> e = encoder.lock ();
+ auto e = encoder.lock ();
if (e) {
e->servers_list_changed ();
}
@@ -126,13 +127,13 @@ J2KEncoder::end ()
So just mop up anything left in the queue here.
*/
- for (list<shared_ptr<DCPVideo> >::iterator i = _queue.begin(); i != _queue.end(); ++i) {
- LOG_GENERAL (N_("Encode left-over frame %1"), (*i)->index ());
+ for (auto i: _queue) {
+ LOG_GENERAL(N_("Encode left-over frame %1"), i->index());
try {
_writer->write (
- shared_ptr<dcp::Data>(new dcp::ArrayData((*i)->encode_locally())),
- (*i)->index(),
- (*i)->eyes()
+ make_shared<dcp::ArrayData>(i->encode_locally()),
+ i->index(),
+ i->eyes()
);
frame_done ();
} catch (std::exception& e) {
@@ -205,7 +206,7 @@ J2KEncoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
*/
rethrow ();
- Frame const position = time.frames_floor(_film->video_frame_rate());
+ auto const position = time.frames_floor(_film->video_frame_rate());
if (_writer->can_fake_write (position)) {
/* We can fake-write this frame */
@@ -224,15 +225,13 @@ J2KEncoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
LOG_DEBUG_ENCODE("Frame @ %1 ENCODE", to_string(time));
/* Queue this new frame for encoding */
LOG_TIMING ("add-frame-to-queue queue=%1", _queue.size ());
- _queue.push_back (shared_ptr<DCPVideo> (
- new DCPVideo (
- pv,
- position,
- _film->video_frame_rate(),
- _film->j2k_bandwidth(),
- _film->resolution()
- )
- ));
+ _queue.push_back (make_shared<DCPVideo>(
+ pv,
+ position,
+ _film->video_frame_rate(),
+ _film->j2k_bandwidth(),
+ _film->resolution()
+ ));
/* The queue might not be empty any more, so notify anything which is
waiting on that.
@@ -292,7 +291,7 @@ try
}
LOG_TIMING ("encoder-wake thread=%1 queue=%2", thread_id(), _queue.size());
- shared_ptr<DCPVideo> vf = _queue.front ();
+ auto vf = _queue.front ();
/* We're about to commit to either encoding this frame or putting it back onto the queue,
so we must not be interrupted until one or other of these things have happened. This
@@ -311,7 +310,7 @@ try
/* We need to encode this input */
if (server) {
try {
- encoded.reset(new dcp::ArrayData(vf->encode_remotely(server.get())));
+ encoded = make_shared<dcp::ArrayData>(vf->encode_remotely(server.get()));
if (remote_backoff > 0) {
LOG_GENERAL ("%1 was lost, but now she is found; removing backoff", server->host_name ());
@@ -334,7 +333,7 @@ try
} else {
try {
LOG_TIMING ("start-local-encode thread=%1 frame=%2", thread_id(), vf->index());
- encoded.reset(new dcp::ArrayData(vf->encode_locally()));
+ encoded = make_shared<dcp::ArrayData>(vf->encode_locally());
LOG_TIMING ("finish-local-encode thread=%1 frame=%2", thread_id(), vf->index());
} catch (std::exception& e) {
/* This is very bad, so don't cope with it, just pass it on */
@@ -380,14 +379,14 @@ J2KEncoder::servers_list_changed ()
boost::mutex::scoped_lock lm (_threads_mutex);
terminate_threads ();
- _threads.reset (new boost::thread_group());
+ _threads = make_shared<boost::thread_group>();
/* XXX: could re-use threads */
if (!Config::instance()->only_servers_encode ()) {
for (int i = 0; i < Config::instance()->master_encoding_threads (); ++i) {
#ifdef DCPOMATIC_LINUX
- boost::thread* t = _threads->create_thread(boost::bind(&J2KEncoder::encoder_thread, this, optional<EncodeServerDescription>()));
+ auto t = _threads->create_thread(boost::bind(&J2KEncoder::encoder_thread, this, optional<EncodeServerDescription>()));
pthread_setname_np (t->native_handle(), "encode-worker");
#else
_threads->create_thread(boost::bind(&J2KEncoder::encoder_thread, this, optional<EncodeServerDescription>()));
diff --git a/src/lib/util.cc b/src/lib/util.cc
index c7b3281da..0aa7e7a28 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.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.
@@ -104,6 +104,7 @@ using std::bad_alloc;
using std::set_terminate;
using std::make_pair;
using std::shared_ptr;
+using std::make_shared;
using boost::thread;
using boost::optional;
using boost::lexical_cast;
@@ -241,7 +242,7 @@ DCPOMATIC_DISABLE_WARNINGS
LONG WINAPI
exception_handler(struct _EXCEPTION_POINTERS * info)
{
- FILE* f = fopen_boost (backtrace_file, "w");
+ auto f = fopen_boost (backtrace_file, "w");
fprintf (f, "C-style exception %d\n", info->ExceptionRecord->ExceptionCode);
fclose(f);
@@ -370,7 +371,7 @@ DCPOMATIC_ENABLE_WARNINGS
/* Add our library directory to the libltdl search path so that
xmlsec can find xmlsec1-openssl.
*/
- boost::filesystem::path lib = directory_containing_executable().parent_path();
+ auto lib = directory_containing_executable().parent_path();
lib /= "Frameworks";
setenv ("LTDL_LIBRARY_PATH", lib.c_str (), 1);
#endif
@@ -398,7 +399,7 @@ DCPOMATIC_ENABLE_WARNINGS
"Hello dolly", dcp::NONE, dcp::Colour(), dcp::Time(), dcp::Time()
);
subs.push_back (StringText(ss, 0));
- render_text (subs, list<shared_ptr<Font> >(), dcp::Size(640, 480), DCPTime(), 24);
+ render_text (subs, list<shared_ptr<Font>>(), dcp::Size(640, 480), DCPTime(), 24);
#endif
Ratio::setup_ratios ();
@@ -479,7 +480,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
char* p = buffer.get ();
int i = 0;
while (i < int64_t (files.size()) && to_do > 0) {
- FILE* f = fopen_boost (files[i], "rb");
+ auto f = fopen_boost (files[i], "rb");
if (!f) {
throw OpenFileError (files[i].string(), errno, OpenFileError::READ);
}
@@ -499,7 +500,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
p = buffer.get ();
i = files.size() - 1;
while (i >= 0 && to_do > 0) {
- FILE* f = fopen_boost (files[i], "rb");
+ auto f = fopen_boost (files[i], "rb");
if (!f) {
throw OpenFileError (files[i].string(), errno, OpenFileError::READ);
}
@@ -606,7 +607,7 @@ valid_image_file (boost::filesystem::path f)
return false;
}
- string ext = f.extension().string();
+ auto ext = f.extension().string();
transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
return (
ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" ||
@@ -623,7 +624,7 @@ valid_sound_file (boost::filesystem::path f)
return false;
}
- string ext = f.extension().string();
+ auto ext = f.extension().string();
transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
return (ext == ".wav" || ext == ".mp3" || ext == ".aif" || ext == ".aiff");
}
@@ -631,7 +632,7 @@ valid_sound_file (boost::filesystem::path f)
bool
valid_j2k_file (boost::filesystem::path f)
{
- string ext = f.extension().string();
+ auto ext = f.extension().string();
transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
return (ext == ".j2k" || ext == ".j2c" || ext == ".jp2");
}
@@ -656,7 +657,7 @@ fit_ratio_within (float ratio, dcp::Size full_frame)
void *
wrapped_av_malloc (size_t s)
{
- void* p = av_malloc (s);
+ auto p = av_malloc (s);
if (!p) {
throw bad_alloc ();
}
@@ -845,7 +846,7 @@ audio_channel_types (list<int> mapped, int channels)
shared_ptr<AudioBuffers>
remap (shared_ptr<const AudioBuffers> input, int output_channels, AudioMapping map)
{
- shared_ptr<AudioBuffers> mapped (new AudioBuffers (output_channels, input->frames()));
+ auto mapped = make_shared<AudioBuffers>(output_channels, input->frames());
mapped->make_silent ();
int to_do = min (map.input_channels(), input->channels());
@@ -954,7 +955,7 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size
{
/* XXX: this is rather inefficient; decoding the image just to get its size */
FFmpegImageProxy proxy (sub.png_image(), VIDEO_RANGE_FULL);
- shared_ptr<Image> image = proxy.image().image;
+ auto image = proxy.image().image;
/* set up rect with height and width */
dcpomatic::Rect<double> rect(0, 0, image->size().width / double(size.width), image->size().height / double(size.height));
@@ -996,7 +997,7 @@ show_jobs_on_console (bool progress)
dcpomatic_sleep_seconds (5);
- list<shared_ptr<Job> > jobs = JobManager::instance()->get();
+ auto jobs = JobManager::instance()->get();
if (!first && progress) {
for (size_t i = 0; i < jobs.size(); ++i) {
@@ -1046,11 +1047,11 @@ show_jobs_on_console (bool progress)
void
copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, boost::function<void (float)> progress)
{
- FILE* f = fopen_boost (from, "rb");
+ auto f = fopen_boost (from, "rb");
if (!f) {
throw OpenFileError (from, errno, OpenFileError::READ);
}
- FILE* t = fopen_boost (to, "wb");
+ auto t = fopen_boost (to, "wb");
if (!t) {
fclose (f);
throw OpenFileError (to, errno, OpenFileError::WRITE);
@@ -1059,7 +1060,7 @@ copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, boost::f
/* on the order of a second's worth of copying */
boost::uintmax_t const chunk = 20 * 1024 * 1024;
- uint8_t* buffer = static_cast<uint8_t*> (malloc(chunk));
+ auto buffer = static_cast<uint8_t*> (malloc(chunk));
if (!buffer) {
throw std::bad_alloc ();
}
@@ -1132,9 +1133,9 @@ decrypt_kdm_with_helpful_error (dcp::EncryptedKDM kdm)
return dcp::DecryptedKDM (kdm, Config::instance()->decryption_chain()->key().get());
} catch (dcp::KDMDecryptionError& e) {
/* Try to flesh out the error a bit */
- string const kdm_subject_name = kdm.recipient_x509_subject_name();
+ auto const kdm_subject_name = kdm.recipient_x509_subject_name();
bool on_chain = false;
- shared_ptr<const dcp::CertificateChain> dc = Config::instance()->decryption_chain();
+ auto dc = Config::instance()->decryption_chain();
for (auto i: dc->root_to_leaf()) {
if (i.subject() == kdm_subject_name) {
on_chain = true;