/*
- Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
int const ReelWriter::_info_size = 48;
+/** @param job Related job, or 0 */
ReelWriter::ReelWriter (
shared_ptr<const Film> film, DCPTimePeriod period, shared_ptr<Job> job, int reel_index, int reel_count, optional<string> content_summary
)
_film->internal_video_asset_dir() / _film->internal_video_asset_filename(_period)
);
- job->sub (_("Checking existing image data"));
+ if (job) {
+ job->sub (_("Checking existing image data"));
+ }
_first_nonexistant_frame = check_existing_picture_asset ();
_picture_asset_writer = _picture_asset->start_write (
void
ReelWriter::write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const
{
- FILE* file = 0;
- boost::filesystem::path info_file = _film->info_file (_period);
-
- bool const read = boost::filesystem::exists (info_file);
-
- if (read) {
- file = fopen_boost (info_file, "r+b");
- } else {
- file = fopen_boost (info_file, "wb");
- }
- if (!file) {
- throw OpenFileError (info_file, errno, read);
- }
- dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET);
- checked_fwrite (&info.offset, sizeof (info.offset), file, info_file);
- checked_fwrite (&info.size, sizeof (info.size), file, info_file);
- checked_fwrite (info.hash.c_str(), info.hash.size(), file, info_file);
- fclose (file);
+ shared_ptr<InfoFileHandle> 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());
}
dcp::FrameInfo
-ReelWriter::read_frame_info (FILE* file, Frame frame, Eyes eyes) const
+ReelWriter::read_frame_info (shared_ptr<InfoFileHandle> info, Frame frame, Eyes eyes) const
{
- dcp::FrameInfo info;
- dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET);
- checked_fread (&info.offset, sizeof(info.offset), file, _film->info_file(_period));
- checked_fread (&info.size, sizeof(info.size), file, _film->info_file(_period));
+ 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());
char hash_buffer[33];
- checked_fread (hash_buffer, 32, file, _film->info_file(_period));
+ checked_fread (hash_buffer, 32, info->get(), info->file());
hash_buffer[32] = '\0';
- info.hash = hash_buffer;
+ frame_info.hash = hash_buffer;
- return info;
+ return frame_info;
}
long
LOG_GENERAL ("Opened existing asset at %1", asset.string());
}
- /* Offset of the last dcp::FrameInfo in the info file */
- int const n = (boost::filesystem::file_size (_film->info_file(_period)) / _info_size) - 1;
- LOG_GENERAL ("The last FI is %1; info file is %2, info size %3", n, boost::filesystem::file_size (_film->info_file(_period)), _info_size);
+ shared_ptr<InfoFileHandle> info_file;
- FILE* info_file = fopen_boost (_film->info_file(_period), "rb");
- if (!info_file) {
+ try {
+ 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);
+
Frame first_nonexistant_frame;
if (_film->three_d ()) {
/* Start looking at the last left frame */
LOG_GENERAL ("Proceeding with first nonexistant frame %1", first_nonexistant_frame);
fclose (asset_file);
- fclose (info_file);
return first_nonexistant_frame;
}
if (_film->interop ()) {
shared_ptr<dcp::InteropSubtitleAsset> s (new dcp::InteropSubtitleAsset ());
s->set_movie_title (_film->name ());
- if (lang.empty()) {
- s->set_language ("Unknown");
+ if (type == TEXT_OPEN_SUBTITLE) {
+ s->set_language (lang.empty() ? "Unknown" : lang);
} else {
- s->set_language (lang);
+ s->set_language (track->language);
}
s->set_reel_number (raw_convert<string> (_reel_index + 1));
asset = s;
} else {
shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset ());
s->set_content_title_text (_film->name ());
- if (!lang.empty()) {
+ if (type == TEXT_OPEN_SUBTITLE && !lang.empty()) {
s->set_language (lang);
+ } else {
+ s->set_language (track->language);
}
s->set_edit_rate (dcp::Fraction (_film->video_frame_rate (), 1));
s->set_reel_number (_reel_index + 1);
shared_ptr<dcp::Subtitle>(
new dcp::SubtitleImage(
i.image->as_png(),
- dcp::Time(period.from.seconds(), _film->video_frame_rate()),
- dcp::Time(period.to.seconds(), _film->video_frame_rate()),
+ dcp::Time(period.from.seconds() - _period.from.seconds(), _film->video_frame_rate()),
+ dcp::Time(period.to.seconds() - _period.from.seconds(), _film->video_frame_rate()),
i.rectangle.x, dcp::HALIGN_LEFT, i.rectangle.y, dcp::VALIGN_TOP,
dcp::Time(), dcp::Time()
)
}
bool
-ReelWriter::existing_picture_frame_ok (FILE* asset_file, FILE* info_file, Frame frame) const
+ReelWriter::existing_picture_frame_ok (FILE* asset_file, shared_ptr<InfoFileHandle> info_file, Frame frame) const
{
LOG_GENERAL ("Checking existing picture frame %1", frame);