X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fwriter.cc;h=8d73b31267a368f768598a9e3e5ab1343f024bef;hb=6bf1fecd1064978bcadd11b8cd56a5b8d9a132a3;hp=59d31d816ea45d06e5b836858d00095708afc58c;hpb=27173512f4ea4f2c324b9488180ba7cbd7173ec3;p=dcpomatic.git diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 59d31d816..8d73b3126 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -71,8 +71,6 @@ using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; -int const Writer::_maximum_frames_in_memory = Config::instance()->num_local_encoding_threads() + 4; - Writer::Writer (shared_ptr f, weak_ptr j) : _film (f) , _job (j) @@ -92,9 +90,6 @@ Writer::Writer (shared_ptr f, weak_ptr j) shared_ptr job = _job.lock (); DCPOMATIC_ASSERT (job); - job->sub (_("Checking existing image data")); - check_existing_picture_mxf (); - /* Create our picture asset in a subdirectory, named according to those film's parameters which affect the video output. We will hard-link it into the DCP later. @@ -106,6 +101,9 @@ Writer::Writer (shared_ptr f, weak_ptr j) _picture_mxf.reset (new dcp::MonoPictureMXF (dcp::Fraction (_film->video_frame_rate (), 1))); } + job->sub (_("Checking existing image data")); + check_existing_picture_mxf (); + _picture_mxf->set_size (_film->frame_size ()); if (_film->encrypted ()) { @@ -151,7 +149,7 @@ Writer::write (shared_ptr encoded, int frame, Eyes eyes) { boost::mutex::scoped_lock lock (_mutex); - while (_queued_full_in_memory > _maximum_frames_in_memory) { + while (_queued_full_in_memory > maximum_frames_in_memory ()) { /* The queue is too big; wait until that is sorted out */ _full_condition.wait (lock); } @@ -184,14 +182,17 @@ Writer::fake_write (int frame, Eyes eyes) { boost::mutex::scoped_lock lock (_mutex); - while (_queued_full_in_memory > _maximum_frames_in_memory) { + while (_queued_full_in_memory > maximum_frames_in_memory ()) { /* The queue is too big; wait until that is sorted out */ _full_condition.wait (lock); } - FILE* ifi = fopen_boost (_film->info_path (frame, eyes), "r"); - dcp::FrameInfo info (ifi); - fclose (ifi); + FILE* file = fopen_boost (_film->info_file (), "rb"); + if (!file) { + throw ReadFileError (_film->info_file ()); + } + dcp::FrameInfo info = read_frame_info (file, frame, eyes); + fclose (file); QueueItem qi; qi.type = QueueItem::FAKE; @@ -263,7 +264,7 @@ try while (true) { - if (_finish || _queued_full_in_memory > _maximum_frames_in_memory || have_sequenced_image_at_queue_head ()) { + if (_finish || _queued_full_in_memory > maximum_frames_in_memory () || have_sequenced_image_at_queue_head ()) { /* We've got something to do: go and do it */ break; } @@ -289,7 +290,11 @@ try if (!_queue.empty() && !have_sequenced_image_at_queue_head()) { LOG_WARNING (N_("Finishing writer with a left-over queue of %1:"), _queue.size()); for (list::const_iterator i = _queue.begin(); i != _queue.end(); ++i) { - LOG_WARNING (N_("- type %1, size %2, frame %3, eyes %4"), i->type, i->size, i->frame, i->eyes); + if (i->type == QueueItem::FULL) { + LOG_WARNING (N_("- type FULL, frame %1, eyes %2"), i->frame, i->eyes); + } else { + LOG_WARNING (N_("- type FAKE, size %1, frame %2, eyes %3"), i->size, i->frame, i->eyes); + } } LOG_WARNING (N_("Last written frame %1, last written eyes %2"), _last_written_frame, _last_written_eyes); } @@ -345,7 +350,7 @@ try } } - while (_queued_full_in_memory > _maximum_frames_in_memory) { + while (_queued_full_in_memory > maximum_frames_in_memory ()) { done_something = true; /* Too many frames in memory which can't yet be written to the stream. Write some FULL frames to disk. @@ -431,9 +436,7 @@ Writer::finish () } /* Hard-link the video MXF into the DCP */ - boost::filesystem::path video_from; - video_from /= _film->internal_video_mxf_dir(); - video_from /= _film->internal_video_mxf_filename(); + boost::filesystem::path video_from = _picture_mxf->file (); boost::filesystem::path video_to; video_to /= _film->dir (_film->dcp_name()); @@ -551,14 +554,14 @@ bool Writer::check_existing_picture_mxf_frame (FILE* mxf, int f, Eyes eyes) { /* Read the frame info as written */ - FILE* ifi = fopen_boost (_film->info_path (f, eyes), "r"); - if (!ifi) { + FILE* file = fopen_boost (_film->info_file (), "rb"); + if (!file) { LOG_GENERAL ("Existing frame %1 has no info file", f); return false; } - dcp::FrameInfo info (ifi); - fclose (ifi); + dcp::FrameInfo info = read_frame_info (file, f, eyes); + fclose (file); if (info.size == 0) { LOG_GENERAL ("Existing frame %1 has no info file", f); return false; @@ -587,28 +590,18 @@ void Writer::check_existing_picture_mxf () { /* Try to open the existing MXF */ - boost::filesystem::path p; - p /= _film->internal_video_mxf_dir (); - p /= _film->internal_video_mxf_filename (); - FILE* mxf = fopen_boost (p, "rb"); + FILE* mxf = fopen_boost (_picture_mxf->file(), "rb"); if (!mxf) { - LOG_GENERAL ("Could not open existing MXF at %1 (errno=%2)", p.string(), errno); + LOG_GENERAL ("Could not open existing MXF at %1 (errno=%2)", _picture_mxf->file().string(), errno); return; } - int N = 0; - for (boost::filesystem::directory_iterator i (_film->info_dir ()); i != boost::filesystem::directory_iterator (); ++i) { - ++N; - } - while (true) { shared_ptr job = _job.lock (); DCPOMATIC_ASSERT (job); - if (N > 0) { - job->set_progress (float (_first_nonexistant_frame) / N); - } + job->set_progress_unknown (); if (_film->three_d ()) { if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_LEFT)) { @@ -690,3 +683,9 @@ operator== (QueueItem const & a, QueueItem const & b) { return a.frame == b.frame && a.eyes == b.eyes; } + +int +Writer::maximum_frames_in_memory () const +{ + return Config::instance()->num_local_encoding_threads() + 4; +}