-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) {
- LOG_GENERAL ("Existing frame %1 has no info file", f);
- return false;
- }
-
- dcp::FrameInfo info (ifi);
- fclose (ifi);
- if (info.size == 0) {
- LOG_GENERAL ("Existing frame %1 has no info file", f);
- return false;
- }
-
- /* Read the data from the MXF and hash it */
- dcpomatic_fseek (mxf, info.offset, SEEK_SET);
- EncodedData data (info.size);
- size_t const read = fread (data.data(), 1, data.size(), mxf);
- if (read != static_cast<size_t> (data.size ())) {
- LOG_GENERAL ("Existing frame %1 is incomplete", f);
- return false;
- }
-
- MD5Digester digester;
- digester.add (data.data(), data.size());
- if (digester.get() != info.hash) {
- LOG_GENERAL ("Existing frame %1 failed hash check", f);
- return false;
- }
-
- return true;
-}
-
-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");
- if (!mxf) {
- LOG_GENERAL ("Could not open existing MXF at %1 (errno=%2)", p.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);
- }
-
- if (_film->three_d ()) {
- if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_LEFT)) {
- break;
- }
- if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_RIGHT)) {
- break;
- }
- } else {
- if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_BOTH)) {
- break;
- }
- }
-
- LOG_GENERAL ("Have existing frame %1", _first_nonexistant_frame);
- ++_first_nonexistant_frame;
- }
-
- fclose (mxf);
-}
-
-/** @param frame Frame index.