X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Freel_writer.cc;h=d742818ae08849bfe81e191c3f922deb01a3b6c0;hb=4a5fcd19ca16447ba8b204986a378072a9c730b2;hp=bc0013ff130ec7230f324f80563114f7f131f8f5;hpb=ddad6389ba1971603a3dbf975b1e5fae95ce6bd6;p=dcpomatic.git diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index bc0013ff1..d742818ae 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2016 Carl Hetherington This file is part of DCP-o-matic. @@ -23,7 +23,7 @@ #include "cross.h" #include "job.h" #include "log.h" -#include "md5_digester.h" +#include "digester.h" #include "font.h" #include "compose.hpp" #include "audio_buffers.h" @@ -60,13 +60,18 @@ using dcp::Data; int const ReelWriter::_info_size = 48; -ReelWriter::ReelWriter (shared_ptr film, DCPTimePeriod period, shared_ptr job) +ReelWriter::ReelWriter ( + shared_ptr film, DCPTimePeriod period, shared_ptr job, int reel_index, int reel_count, optional content_summary + ) : _film (film) , _period (period) , _first_nonexistant_frame (0) , _last_written_video_frame (-1) , _last_written_eyes (EYES_RIGHT) , _total_written_audio_frames (0) + , _reel_index (reel_index) + , _reel_count (reel_count) + , _content_summary (content_summary) { /* Create our picture asset in a subdirectory, named according to those film's parameters which affect the video output. We will hard-link @@ -107,11 +112,13 @@ ReelWriter::ReelWriter (shared_ptr film, DCPTimePeriod period, share _sound_asset->set_key (_film->key ()); } + DCPOMATIC_ASSERT (_film->directory()); + /* Write the sound asset into the film directory so that we leave the creation of the DCP directory until the last minute. */ _sound_asset_writer = _sound_asset->start_write ( - _film->directory() / audio_asset_filename (_sound_asset), + _film->directory().get() / audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary), _film->interop() ? dcp::INTEROP : dcp::SMPTE ); } @@ -123,13 +130,14 @@ ReelWriter::write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const { FILE* file = 0; boost::filesystem::path info_file = _film->info_file (_period); - if (boost::filesystem::exists (info_file)) { + bool const read = boost::filesystem::exists (info_file); + if (read) { file = fopen_boost (info_file, "r+b"); } else { file = fopen_boost (info_file, "wb"); } if (!file) { - throw OpenFileError (info_file); + throw OpenFileError (info_file, errno, read); } dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET); fwrite (&info.offset, sizeof (info.offset), 1, file); @@ -175,12 +183,13 @@ void ReelWriter::check_existing_picture_asset () { /* Try to open the existing asset */ - FILE* asset_file = fopen_boost (_picture_asset->file(), "rb"); + DCPOMATIC_ASSERT (_picture_asset->file()); + FILE* asset_file = fopen_boost (_picture_asset->file().get(), "rb"); if (!asset_file) { - LOG_GENERAL ("Could not open existing asset at %1 (errno=%2)", _picture_asset->file().string(), errno); + LOG_GENERAL ("Could not open existing asset at %1 (errno=%2)", _picture_asset->file()->string(), errno); return; } else { - LOG_GENERAL ("Opened existing asset at %1", _picture_asset->file().string()); + LOG_GENERAL ("Opened existing asset at %1", _picture_asset->file()->string()); } /* Offset of the last dcp::FrameInfo in the info file */ @@ -263,10 +272,11 @@ ReelWriter::finish () /* Hard-link any video asset file into the DCP */ if (_picture_asset) { - boost::filesystem::path video_from = _picture_asset->file (); + DCPOMATIC_ASSERT (_picture_asset->file()); + boost::filesystem::path video_from = _picture_asset->file().get(); boost::filesystem::path video_to; video_to /= _film->dir (_film->dcp_name()); - video_to /= video_asset_filename (_picture_asset); + video_to /= video_asset_filename (_picture_asset, _reel_index, _reel_count, _content_summary); boost::system::error_code ec; boost::filesystem::create_hard_link (video_from, video_to, ec); @@ -286,13 +296,14 @@ ReelWriter::finish () if (_sound_asset) { boost::filesystem::path audio_to; audio_to /= _film->dir (_film->dcp_name ()); - audio_to /= audio_asset_filename (_sound_asset); + string const aaf = audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary); + audio_to /= aaf; boost::system::error_code ec; - boost::filesystem::rename (_film->file (audio_asset_filename (_sound_asset)), audio_to, ec); + boost::filesystem::rename (_film->file (aaf), audio_to, ec); if (ec) { throw FileError ( - String::compose (_("could not move audio asset into the DCP (%1)"), ec.value ()), audio_asset_filename (_sound_asset) + String::compose (_("could not move audio asset into the DCP (%1)"), ec.value ()), aaf ); } @@ -328,7 +339,9 @@ ReelWriter::create_reel (list const & refs, listadd (reel_picture_asset); + /* If we have a hash for this asset in the CPL, assume that it is correct */ if (reel_picture_asset->hash()) { reel_picture_asset->asset_ref()->set_hash (reel_picture_asset->hash().get()); @@ -417,16 +430,14 @@ ReelWriter::create_reel (list const & refs, list job) +ReelWriter::calculate_digests (boost::function set_progress) { - job->sub (_("Computing image digest")); if (_picture_asset) { - _picture_asset->hash (boost::bind (&Job::set_progress, job.get(), _1, false)); + _picture_asset->hash (set_progress); } if (_sound_asset) { - job->sub (_("Computing audio digest")); - _sound_asset->hash (boost::bind (&Job::set_progress, job.get(), _1, false)); + _sound_asset->hash (set_progress); } } @@ -473,11 +484,14 @@ ReelWriter::write (PlayerSubtitles subs) s->set_reel_number (1); s->set_time_code_rate (_film->video_frame_rate ()); s->set_start_time (dcp::Time ()); + if (_film->encrypted ()) { + s->set_key (_film->key ()); + } _subtitle_asset = s; } } - BOOST_FOREACH (dcp::SubtitleString i, subs.text) { + BOOST_FOREACH (SubtitleString i, subs.text) { i.set_in (i.in() - dcp::Time (_period.from.seconds(), i.in().tcr)); i.set_out (i.out() - dcp::Time (_period.from.seconds(), i.out().tcr)); _subtitle_asset->add (i); @@ -505,7 +519,7 @@ ReelWriter::existing_picture_frame_ok (FILE* asset_file, FILE* info_file) const LOG_GENERAL ("Existing frame %1 is incomplete", _first_nonexistant_frame); ok = false; } else { - MD5Digester digester; + Digester digester; digester.add (data.data().get(), data.size()); LOG_GENERAL ("Hash %1 vs %2", digester.get(), info.hash); if (digester.get() != info.hash) {