-void
-Writer::check_existing_picture_asset (Reel& reel)
-{
- /* Try to open the existing asset */
- FILE* asset_file = fopen_boost (reel.picture_asset->file(), "rb");
- if (!asset_file) {
- LOG_GENERAL ("Could not open existing asset at %1 (errno=%2)", reel.picture_asset->file().string(), errno);
- return;
- }
-
- /* Offset of the last dcp::FrameInfo in the info file */
- int const n = (boost::filesystem::file_size (_film->info_file(reel.period)) / _info_size) - 1;
-
- FILE* info_file = fopen_boost (_film->info_file(reel.period), "rb");
- if (!info_file) {
- LOG_GENERAL_NC ("Could not open film info file");
- fclose (asset_file);
- return;
- }
-
- if (_film->three_d ()) {
- /* Start looking at the last left frame */
- reel.first_nonexistant_frame = n / 2;
- } else {
- reel.first_nonexistant_frame = n;
- }
-
- bool ok = false;
-
- while (!ok) {
- /* Read the data from the info file; for 3D we just check the left
- frames until we find a good one.
- */
- dcp::FrameInfo info = read_frame_info (info_file, reel.first_nonexistant_frame, _film->three_d () ? EYES_LEFT : EYES_BOTH);
-
- ok = true;
-
- /* Read the data from the asset and hash it */
- dcpomatic_fseek (asset_file, info.offset, SEEK_SET);
- Data data (info.size);
- size_t const read = fread (data.data().get(), 1, data.size(), asset_file);
- if (read != static_cast<size_t> (data.size ())) {
- LOG_GENERAL ("Existing frame %1 is incomplete", reel.first_nonexistant_frame);
- ok = false;
- } else {
- MD5Digester digester;
- digester.add (data.data().get(), data.size());
- if (digester.get() != info.hash) {
- LOG_GENERAL ("Existing frame %1 failed hash check", reel.first_nonexistant_frame);
- ok = false;
- }
- }
-
- if (!ok) {
- --reel.first_nonexistant_frame;
- }
- }
-
- if (!_film->three_d ()) {
- /* If we are doing 3D we might have found a good L frame with no R, so only
- do this if we're in 2D and we've just found a good B(oth) frame.
- */
- ++reel.first_nonexistant_frame;
- }
-
- fclose (asset_file);
- fclose (info_file);
-}
-