Fix ID numbering.
[dcpomatic.git] / src / lib / writer.cc
index 909b1e4484d1c19b1cbc56b751131a098215534a..4270a42a7684a76f2f64a34392e26e28bffb501f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     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
@@ -92,9 +92,6 @@ Writer::Writer (shared_ptr<const Film> f, weak_ptr<Job> j)
        shared_ptr<Job> 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 +103,9 @@ Writer::Writer (shared_ptr<const Film> f, weak_ptr<Job> 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 ()) {
@@ -189,12 +189,12 @@ Writer::fake_write (int frame, Eyes eyes)
                _full_condition.wait (lock);
        }
        
-       FILE* ifi = fopen_boost (_film->info_path (frame, eyes), "r");
-       if (!ifi) {
-               throw ReadFileError (_film->info_path (frame, eyes));
+       FILE* file = fopen_boost (_film->info_file (), "rb");
+       if (!file) {
+               throw ReadFileError (_film->info_file ());
        }
-       dcp::FrameInfo info (ifi);
-       fclose (ifi);
+       dcp::FrameInfo info = read_frame_info (file, frame, eyes);
+       fclose (file);
        
        QueueItem qi;
        qi.type = QueueItem::FAKE;
@@ -438,9 +438,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());
@@ -558,14 +556,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;
@@ -594,28 +592,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 = _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)) {