#include "cross.h"
#include "audio_buffers.h"
#include "version.h"
-#include "font.h"
+#include "font_data.h"
#include "util.h"
#include "reel_writer.h"
#include "text_content.h"
using std::min;
using std::max;
using std::vector;
-using boost::shared_ptr;
-using boost::weak_ptr;
-using boost::dynamic_pointer_cast;
+using std::shared_ptr;
+using std::weak_ptr;
+using std::dynamic_pointer_cast;
using boost::optional;
#if BOOST_VERSION >= 106100
using namespace boost::placeholders;
using dcp::ArrayData;
using namespace dcpomatic;
-Writer::Writer (weak_ptr<const Film> weak_film, weak_ptr<Job> j)
+
+static
+void
+ignore_progress (float)
+{
+
+}
+
+
+/** @param j Job to report progress to, or 0.
+ * @param text_only true to enable only the text (subtitle/ccap) parts of the writer.
+ */
+Writer::Writer (weak_ptr<const Film> weak_film, weak_ptr<Job> j, bool text_only)
: WeakConstFilm (weak_film)
, _job (j)
, _finish (false)
, _fake_written (0)
, _repeat_written (0)
, _pushed_to_disk (0)
+ , _text_only (text_only)
+ , _have_subtitles (false)
{
shared_ptr<Job> job = _job.lock ();
- DCPOMATIC_ASSERT (job);
int reel_index = 0;
list<DCPTimePeriod> const reels = film()->reels();
BOOST_FOREACH (DCPTimePeriod p, reels) {
- _reels.push_back (ReelWriter(film(), p, job, reel_index++, reels.size()));
+ _reels.push_back (ReelWriter(weak_film, p, job, reel_index++, reels.size(), text_only));
}
_last_written.resize (reels.size());
void
Writer::start ()
{
- _thread = boost::thread (boost::bind(&Writer::thread, this));
+ if (!_text_only) {
+ _thread = boost::thread (boost::bind(&Writer::thread, this));
#ifdef DCPOMATIC_LINUX
- pthread_setname_np (_thread.native_handle(), "writer");
+ pthread_setname_np (_thread.native_handle(), "writer");
#endif
+ }
}
Writer::~Writer ()
{
- terminate_thread (false);
+ if (!_text_only) {
+ terminate_thread (false);
+ }
}
/** Pass a video frame to the writer for writing to disk at some point.
}
}
+
+/** @param output_dcp Path to DCP folder to write */
void
-Writer::finish ()
+Writer::finish (boost::filesystem::path output_dcp)
{
- if (!_thread.joinable()) {
- return;
+ if (_thread.joinable()) {
+ LOG_GENERAL_NC ("Terminating writer thread");
+ terminate_thread (true);
}
- LOG_GENERAL_NC ("Terminating writer thread");
-
- terminate_thread (true);
-
LOG_GENERAL_NC ("Finishing ReelWriters");
BOOST_FOREACH (ReelWriter& i, _reels) {
- i.finish ();
+ i.finish (output_dcp);
}
LOG_GENERAL_NC ("Writing XML");
- dcp::DCP dcp (film()->dir(film()->dcp_name()));
+ dcp::DCP dcp (output_dcp);
shared_ptr<dcp::CPL> cpl (
new dcp::CPL (
/* Calculate digests for each reel in parallel */
shared_ptr<Job> job = _job.lock ();
- job->sub (_("Computing digests"));
+ if (job) {
+ job->sub (_("Computing digests"));
+ }
boost::asio::io_service service;
boost::thread_group pool;
pool.create_thread (boost::bind (&boost::asio::io_service::run, &service));
}
- boost::function<void (float)> set_progress = boost::bind (&Writer::set_digest_progress, this, job.get(), _1);
+ boost::function<void (float)> set_progress;
+ if (job) {
+ set_progress = boost::bind (&Writer::set_digest_progress, this, job.get(), _1);
+ } else {
+ set_progress = &ignore_progress;
+ }
+
BOOST_FOREACH (ReelWriter& i, _reels) {
service.post (boost::bind (&ReelWriter::calculate_digests, &i, set_progress));
}
/* Add reels */
BOOST_FOREACH (ReelWriter& i, _reels) {
- cpl->add (i.create_reel (_reel_assets, _fonts));
+ cpl->add (i.create_reel(_reel_assets, _fonts, output_dcp, _have_subtitles, _have_closed_captions));
}
/* Add metadata */
N_("Wrote %1 FULL, %2 FAKE, %3 REPEAT, %4 pushed to disk"), _full_written, _fake_written, _repeat_written, _pushed_to_disk
);
- write_cover_sheet ();
+ write_cover_sheet (output_dcp);
}
void
-Writer::write_cover_sheet ()
+Writer::write_cover_sheet (boost::filesystem::path output_dcp)
{
boost::filesystem::path const cover = film()->file("COVER_SHEET.txt");
FILE* f = fopen_boost (cover, "w");
boost::uintmax_t size = 0;
for (
- boost::filesystem::recursive_directory_iterator i = boost::filesystem::recursive_directory_iterator(film()->dir(film()->dcp_name()));
+ boost::filesystem::recursive_directory_iterator i = boost::filesystem::recursive_directory_iterator(output_dcp);
i != boost::filesystem::recursive_directory_iterator();
++i) {
if (boost::filesystem::is_regular_file (i->path ())) {
switch (type) {
case TEXT_OPEN_SUBTITLE:
reel = &_subtitle_reel;
+ _have_subtitles = true;
break;
case TEXT_CLOSED_CAPTION:
DCPOMATIC_ASSERT (track);
DCPOMATIC_ASSERT (_caption_reels.find(*track) != _caption_reels.end());
reel = &_caption_reels[*track];
+ _have_closed_captions.insert (*track);
break;
default:
DCPOMATIC_ASSERT (false);
}
void
-Writer::write (list<shared_ptr<Font> > fonts)
+Writer::write (vector<FontData> fonts)
{
/* Just keep a list of unique fonts and we'll deal with them in ::finish */
- BOOST_FOREACH (shared_ptr<Font> i, fonts) {
+ BOOST_FOREACH (FontData const& i, fonts) {
bool got = false;
- BOOST_FOREACH (shared_ptr<Font> j, _fonts) {
- if (*i == *j) {
+ BOOST_FOREACH (FontData const& j, _fonts) {
+ if (i == j) {
got = true;
}
}