Merge branch '1.0-alt-loop' into 1.0
[dcpomatic.git] / src / lib / writer.cc
index 35874581b62d829b74d9b1399f6fce36a20ee620..c5360a122f4e0afa277abec1cdd24a5ead2dd2ed 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include <fstream>
+#include <cerrno>
 #include <libdcp/picture_asset.h>
 #include <libdcp/sound_asset.h>
 #include <libdcp/picture_frame.h>
@@ -88,7 +89,7 @@ Writer::Writer (shared_ptr<const Film> f, shared_ptr<Job> j)
                        _film->dcp_audio_mxf_filename (),
                        _film->dcp_video_frame_rate (),
                        _film->dcp_audio_channels (),
-                       _film->dcp_audio_frame_rate()
+                       _film->dcp_audio_frame_rate ()
                        )
                );
        
@@ -133,7 +134,6 @@ Writer::fake_write (int frame)
 void
 Writer::write (shared_ptr<const AudioBuffers> audio)
 {
-       cout << "W: audio " << audio->frames() << "\n";
        _sound_asset_writer->write (audio->data(), audio->frames());
 }
 
@@ -204,8 +204,10 @@ try
                        }
                        lock.lock ();
                        
-                       if (_film->length ()) {
-                               _job->set_progress (float(_full_written + _fake_written + _repeat_written) / _film->time_to_video_frames (_film->length()));
+                       if (_film->length()) {
+                               _job->set_progress (
+                                       float (_full_written + _fake_written + _repeat_written) / _film->time_to_video_frames (_film->length())
+                                       );
                        }
 
                        ++_last_written_frame;
@@ -343,8 +345,9 @@ Writer::check_existing_picture_mxf ()
        boost::filesystem::path p;
        p /= _film->internal_video_mxf_dir ();
        p /= _film->internal_video_mxf_filename ();
-       FILE* mxf = fopen (p.string().c_str(), N_("rb"));
+       FILE* mxf = fopen (p.string().c_str(), "rb");
        if (!mxf) {
+               _film->log()->log (String::compose ("Could not open existing MXF at %1 (errno=%2)", p.string(), errno));
                return;
        }
 
@@ -357,15 +360,19 @@ Writer::check_existing_picture_mxf ()
                /* Read the data from the MXF and hash it */
                fseek (mxf, info.offset, SEEK_SET);
                EncodedData data (info.size);
-               fread (data.data(), 1, data.size(), mxf);
-               string const existing_hash = md5_digest (data.data(), data.size());
+               size_t const read = fread (data.data(), 1, data.size(), mxf);
+               if (read != static_cast<size_t> (data.size ())) {
+                       _film->log()->log (String::compose ("Existing frame %1 is incomplete", _first_nonexistant_frame));
+                       break;
+               }
                
+               string const existing_hash = md5_digest (data.data(), data.size());
                if (existing_hash != info.hash) {
-                       _film->log()->log (String::compose (N_("Existing frame %1 failed hash check"), _first_nonexistant_frame));
+                       _film->log()->log (String::compose ("Existing frame %1 failed hash check", _first_nonexistant_frame));
                        break;
                }
 
-               _film->log()->log (String::compose (N_("Have existing frame %1"), _first_nonexistant_frame));
+               _film->log()->log (String::compose ("Have existing frame %1", _first_nonexistant_frame));
                ++_first_nonexistant_frame;
        }