X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Freel_writer.cc;h=d64cfb81a4a6b553778fcef43bafa3aa0d7233fc;hb=fcba100f0dfd1d4214291abb76f22ebd696c24d4;hp=b5a95d8b1d6e03a1b214632bac04318f133bb9f7;hpb=313319ba2d8544bc25524e02e634804a503b54f1;p=dcpomatic.git diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index b5a95d8b1..d64cfb81a 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -28,6 +28,7 @@ #include "film.h" #include "font_data.h" #include "image.h" +#include "image_png.h" #include "job.h" #include "log.h" #include "reel_writer.h" @@ -207,10 +208,10 @@ void ReelWriter::write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const { auto handle = film()->info_file_handle(_period, false); - dcpomatic_fseek (handle->get(), frame_info_position(frame, eyes), SEEK_SET); - checked_fwrite (&info.offset, sizeof(info.offset), handle->get(), handle->file()); - checked_fwrite (&info.size, sizeof (info.size), handle->get(), handle->file()); - checked_fwrite (info.hash.c_str(), info.hash.size(), handle->get(), handle->file()); + handle->get().seek(frame_info_position(frame, eyes), SEEK_SET); + handle->get().checked_write(&info.offset, sizeof(info.offset)); + handle->get().checked_write(&info.size, sizeof(info.size)); + handle->get().checked_write(info.hash.c_str(), info.hash.size()); } @@ -218,12 +219,12 @@ dcp::FrameInfo ReelWriter::read_frame_info (shared_ptr info, Frame frame, Eyes eyes) const { dcp::FrameInfo frame_info; - dcpomatic_fseek (info->get(), frame_info_position(frame, eyes), SEEK_SET); - checked_fread (&frame_info.offset, sizeof(frame_info.offset), info->get(), info->file()); - checked_fread (&frame_info.size, sizeof(frame_info.size), info->get(), info->file()); + info->get().seek(frame_info_position(frame, eyes), SEEK_SET); + info->get().checked_read(&frame_info.offset, sizeof(frame_info.offset)); + info->get().checked_read(&frame_info.size, sizeof(frame_info.size)); char hash_buffer[33]; - checked_fread (hash_buffer, 32, info->get(), info->file()); + info->get().checked_read(hash_buffer, 32); hash_buffer[32] = '\0'; frame_info.hash = hash_buffer; @@ -259,7 +260,7 @@ ReelWriter::check_existing_picture_asset (boost::filesystem::path asset) } /* Try to open the existing asset */ - auto asset_file = fopen_boost (asset, "rb"); + dcp::File asset_file(asset, "rb"); if (!asset_file) { LOG_GENERAL ("Could not open existing asset at %1 (errno=%2)", asset.string(), errno); return 0; @@ -273,13 +274,12 @@ ReelWriter::check_existing_picture_asset (boost::filesystem::path asset) info_file = film()->info_file_handle (_period, true); } catch (OpenFileError &) { LOG_GENERAL_NC ("Could not open film info file"); - fclose (asset_file); return 0; } /* Offset of the last dcp::FrameInfo in the info file */ - int const n = (boost::filesystem::file_size(info_file->file()) / _info_size) - 1; - LOG_GENERAL ("The last FI is %1; info file is %2, info size %3", n, boost::filesystem::file_size(info_file->file()), _info_size); + int const n = (boost::filesystem::file_size(info_file->get().path()) / _info_size) - 1; + LOG_GENERAL ("The last FI is %1; info file is %2, info size %3", n, boost::filesystem::file_size(info_file->get().path()), _info_size); Frame first_nonexistant_frame; if (film()->three_d()) { @@ -302,8 +302,6 @@ ReelWriter::check_existing_picture_asset (boost::filesystem::path asset) LOG_GENERAL ("Proceeding with first nonexistant frame %1", first_nonexistant_frame); - fclose (asset_file); - return first_nonexistant_frame; } @@ -461,6 +459,9 @@ maybe_add_text ( shared_ptr asset, int64_t picture_duration, shared_ptr reel, + int reel_index, + int reel_count, + optional content_summary, list const & refs, vector const & fonts, dcp::ArrayData default_font, @@ -483,7 +484,7 @@ maybe_add_text ( if (auto interop = dynamic_pointer_cast(asset)) { auto directory = output_dcp / interop->id (); boost::filesystem::create_directories (directory); - interop->write (directory / ("sub_" + interop->id() + ".xml")); + interop->write (directory / subtitle_asset_filename(asset, reel_index, reel_count, content_summary)); reel_asset = make_shared ( interop, dcp::Fraction(film->video_frame_rate(), 1), @@ -498,7 +499,7 @@ maybe_add_text ( */ smpte->set_intrinsic_duration(picture_duration); smpte->write ( - output_dcp / ("sub_" + asset->id() + ".mxf") + output_dcp / subtitle_asset_filename(asset, reel_index, reel_count, content_summary) ); reel_asset = make_shared ( smpte, @@ -645,7 +646,7 @@ ReelWriter::create_reel_text ( ) const { auto subtitle = maybe_add_text ( - _subtitle_asset, duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only + _subtitle_asset, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, _default_font, film(), _period, output_dcp, _text_only ); if (subtitle) { @@ -659,6 +660,9 @@ ReelWriter::create_reel_text ( empty_text_asset(TextType::OPEN_SUBTITLE, optional(), true), duration, reel, + _reel_index, + _reel_count, + _content_summary, refs, fonts, _default_font, @@ -671,7 +675,7 @@ ReelWriter::create_reel_text ( for (auto const& i: _closed_caption_assets) { auto a = maybe_add_text ( - i.second, duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only + i.second, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, _default_font, film(), _period, output_dcp, _text_only ); DCPOMATIC_ASSERT (a); a->set_annotation_text (i.first.name); @@ -685,7 +689,19 @@ ReelWriter::create_reel_text ( /* Make empty tracks for anything we've been asked to ensure but that we haven't added */ for (auto i: ensure_closed_captions) { auto a = maybe_add_text ( - empty_text_asset(TextType::CLOSED_CAPTION, i, true), duration, reel, refs, fonts, _default_font, film(), _period, output_dcp, _text_only + empty_text_asset(TextType::CLOSED_CAPTION, i, true), + duration, + reel, + _reel_index, + _reel_count, + _content_summary, + refs, + fonts, + _default_font, + film(), + _period, + output_dcp, + _text_only ); DCPOMATIC_ASSERT (a); a->set_annotation_text (i.name); @@ -908,7 +924,7 @@ ReelWriter::write (PlayerText subs, TextType type, optional track, for (auto i: subs.bitmap) { asset->add ( make_shared( - i.image->as_png(), + image_as_png(i.image), dcp::Time(period.from.seconds() - _period.from.seconds(), tcr), dcp::Time(period.to.seconds() - _period.from.seconds(), tcr), i.rectangle.x, dcp::HAlign::LEFT, i.rectangle.y, dcp::VAlign::TOP, @@ -920,7 +936,7 @@ ReelWriter::write (PlayerText subs, TextType type, optional track, bool -ReelWriter::existing_picture_frame_ok (FILE* asset_file, shared_ptr info_file, Frame frame) const +ReelWriter::existing_picture_frame_ok (dcp::File& asset_file, shared_ptr info_file, Frame frame) const { LOG_GENERAL ("Checking existing picture frame %1", frame); @@ -932,9 +948,9 @@ ReelWriter::existing_picture_frame_ok (FILE* asset_file, shared_ptr (data.size ())) { LOG_GENERAL ("Existing frame %1 is incomplete", frame);