Remove debug code.
[dcpomatic.git] / src / lib / writer.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "writer.h"
21 #include "compose.hpp"
22 #include "film.h"
23 #include "ratio.h"
24 #include "log.h"
25 #include "dcp_video.h"
26 #include "dcp_content_type.h"
27 #include "audio_mapping.h"
28 #include "config.h"
29 #include "job.h"
30 #include "cross.h"
31 #include "audio_buffers.h"
32 #include "md5_digester.h"
33 #include "encoded_data.h"
34 #include "version.h"
35 #include "font.h"
36 #include <dcp/mono_picture_mxf.h>
37 #include <dcp/stereo_picture_mxf.h>
38 #include <dcp/sound_mxf.h>
39 #include <dcp/sound_mxf_writer.h>
40 #include <dcp/reel.h>
41 #include <dcp/reel_mono_picture_asset.h>
42 #include <dcp/reel_stereo_picture_asset.h>
43 #include <dcp/reel_sound_asset.h>
44 #include <dcp/reel_subtitle_asset.h>
45 #include <dcp/dcp.h>
46 #include <dcp/cpl.h>
47 #include <dcp/signer.h>
48 #include <dcp/interop_subtitle_content.h>
49 #include <fstream>
50 #include <cerrno>
51
52 #include "i18n.h"
53
54 #define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
55 #define LOG_TIMING(...) _film->log()->microsecond_log (String::compose (__VA_ARGS__), Log::TYPE_TIMING);
56 #define LOG_WARNING_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_WARNING);
57 #define LOG_WARNING(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_WARNING);
58 #define LOG_ERROR(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_ERROR);
59 #define LOG_DEBUG(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_DEBUG);
60 #define LOG_DEBUG_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_DEBUG);
61
62 /* OS X strikes again */
63 #undef set_key
64
65 using std::make_pair;
66 using std::pair;
67 using std::string;
68 using std::list;
69 using std::cout;
70 using boost::shared_ptr;
71 using boost::weak_ptr;
72 using boost::dynamic_pointer_cast;
73
74 int const Writer::_maximum_frames_in_memory = Config::instance()->num_local_encoding_threads() + 4;
75
76 Writer::Writer (shared_ptr<const Film> f, weak_ptr<Job> j)
77         : _film (f)
78         , _job (j)
79         , _first_nonexistant_frame (0)
80         , _thread (0)
81         , _finish (false)
82         , _queued_full_in_memory (0)
83         , _last_written_frame (-1)
84         , _last_written_eyes (EYES_RIGHT)
85         , _full_written (0)
86         , _fake_written (0)
87         , _pushed_to_disk (0)
88 {
89         /* Remove any old DCP */
90         boost::filesystem::remove_all (_film->dir (_film->dcp_name ()));
91
92         shared_ptr<Job> job = _job.lock ();
93         DCPOMATIC_ASSERT (job);
94
95         job->sub (_("Checking existing image data"));
96         check_existing_picture_mxf ();
97
98         /* Create our picture asset in a subdirectory, named according to those
99            film's parameters which affect the video output.  We will hard-link
100            it into the DCP later.
101         */
102
103         if (_film->three_d ()) {
104                 _picture_mxf.reset (new dcp::StereoPictureMXF (dcp::Fraction (_film->video_frame_rate (), 1)));
105         } else {
106                 _picture_mxf.reset (new dcp::MonoPictureMXF (dcp::Fraction (_film->video_frame_rate (), 1)));
107         }
108
109         _picture_mxf->set_size (_film->frame_size ());
110
111         if (_film->encrypted ()) {
112                 _picture_mxf->set_key (_film->key ());
113         }
114         
115         _picture_mxf_writer = _picture_mxf->start_write (
116                 _film->internal_video_mxf_dir() / _film->internal_video_mxf_filename(),
117                 _film->interop() ? dcp::INTEROP : dcp::SMPTE,
118                 _first_nonexistant_frame > 0
119                 );
120
121         if (_film->audio_channels ()) {
122                 _sound_mxf.reset (new dcp::SoundMXF (dcp::Fraction (_film->video_frame_rate(), 1), _film->audio_frame_rate (), _film->audio_channels ()));
123
124                 if (_film->encrypted ()) {
125                         _sound_mxf->set_key (_film->key ());
126                 }
127         
128                 /* Write the sound MXF into the film directory so that we leave the creation
129                    of the DCP directory until the last minute.
130                 */
131                 _sound_mxf_writer = _sound_mxf->start_write (_film->directory() / _film->audio_mxf_filename(), _film->interop() ? dcp::INTEROP : dcp::SMPTE);
132         }
133
134         /* Check that the signer is OK if we need one */
135         if (_film->is_signed() && !Config::instance()->signer()->valid ()) {
136                 throw InvalidSignerError ();
137         }
138
139         _thread = new boost::thread (boost::bind (&Writer::thread, this));
140
141         job->sub (_("Encoding image data"));
142 }
143
144 Writer::~Writer ()
145 {
146         terminate_thread (false);
147 }
148
149 void
150 Writer::write (shared_ptr<const EncodedData> encoded, int frame, Eyes eyes)
151 {
152         boost::mutex::scoped_lock lock (_mutex);
153
154         while (_queued_full_in_memory > _maximum_frames_in_memory) {
155                 /* The queue is too big; wait until that is sorted out */
156                 _full_condition.wait (lock);
157         }
158
159         QueueItem qi;
160         qi.type = QueueItem::FULL;
161         qi.encoded = encoded;
162         qi.frame = frame;
163
164         if (_film->three_d() && eyes == EYES_BOTH) {
165                 /* 2D material in a 3D DCP; fake the 3D */
166                 qi.eyes = EYES_LEFT;
167                 _queue.push_back (qi);
168                 ++_queued_full_in_memory;
169                 qi.eyes = EYES_RIGHT;
170                 _queue.push_back (qi);
171                 ++_queued_full_in_memory;
172         } else {
173                 qi.eyes = eyes;
174                 _queue.push_back (qi);
175                 ++_queued_full_in_memory;
176         }
177
178         /* Now there's something to do: wake anything wait()ing on _empty_condition */
179         _empty_condition.notify_all ();
180 }
181
182 void
183 Writer::fake_write (int frame, Eyes eyes)
184 {
185         boost::mutex::scoped_lock lock (_mutex);
186
187         while (_queued_full_in_memory > _maximum_frames_in_memory) {
188                 /* The queue is too big; wait until that is sorted out */
189                 _full_condition.wait (lock);
190         }
191         
192         FILE* ifi = fopen_boost (_film->info_path (frame, eyes), "r");
193         dcp::FrameInfo info (ifi);
194         fclose (ifi);
195         
196         QueueItem qi;
197         qi.type = QueueItem::FAKE;
198         qi.size = info.size;
199         qi.frame = frame;
200         if (_film->three_d() && eyes == EYES_BOTH) {
201                 qi.eyes = EYES_LEFT;
202                 _queue.push_back (qi);
203                 qi.eyes = EYES_RIGHT;
204                 _queue.push_back (qi);
205         } else {
206                 qi.eyes = eyes;
207                 _queue.push_back (qi);
208         }
209
210         /* Now there's something to do: wake anything wait()ing on _empty_condition */
211         _empty_condition.notify_all ();
212 }
213
214 /** This method is not thread safe */
215 void
216 Writer::write (shared_ptr<const AudioBuffers> audio)
217 {
218         if (_sound_mxf_writer) {
219                 _sound_mxf_writer->write (audio->data(), audio->frames());
220         }
221 }
222
223 /** This must be called from Writer::thread() with an appropriate lock held */
224 bool
225 Writer::have_sequenced_image_at_queue_head ()
226 {
227         if (_queue.empty ()) {
228                 return false;
229         }
230
231         _queue.sort ();
232
233         /* The queue should contain only EYES_LEFT/EYES_RIGHT pairs or EYES_BOTH */
234
235         if (_queue.front().eyes == EYES_BOTH) {
236                 /* 2D */
237                 return _queue.front().frame == (_last_written_frame + 1);
238         }
239
240         /* 3D */
241
242         if (_last_written_eyes == EYES_LEFT && _queue.front().frame == _last_written_frame && _queue.front().eyes == EYES_RIGHT) {
243                 return true;
244         }
245
246         if (_last_written_eyes == EYES_RIGHT && _queue.front().frame == (_last_written_frame + 1) && _queue.front().eyes == EYES_LEFT) {
247                 return true;
248         }
249
250         return false;
251 }
252
253 void
254 Writer::thread ()
255 try
256 {
257         while (true)
258         {
259                 boost::mutex::scoped_lock lock (_mutex);
260
261                 /* This is for debugging only */
262                 bool done_something = false;
263
264                 while (true) {
265                         
266                         if (_finish || _queued_full_in_memory > _maximum_frames_in_memory || have_sequenced_image_at_queue_head ()) {
267                                 /* We've got something to do: go and do it */
268                                 break;
269                         }
270
271                         /* Nothing to do: wait until something happens which may indicate that we do */
272                         LOG_TIMING (N_("writer sleeps with a queue of %1"), _queue.size());
273                         _empty_condition.wait (lock);
274                         LOG_TIMING (N_("writer wakes with a queue of %1"), _queue.size());
275                 }
276
277                 if (_finish && _queue.empty()) {
278                         return;
279                 }
280
281                 /* We stop here if we have been asked to finish, and if either the queue
282                    is empty or we do not have a sequenced image at its head (if this is the
283                    case we will never terminate as no new frames will be sent once
284                    _finish is true).
285                 */
286                 if (_finish && (!have_sequenced_image_at_queue_head() || _queue.empty())) {
287                         done_something = true;
288                         /* (Hopefully temporarily) log anything that was not written */
289                         if (!_queue.empty() && !have_sequenced_image_at_queue_head()) {
290                                 LOG_WARNING (N_("Finishing writer with a left-over queue of %1:"), _queue.size());
291                                 for (list<QueueItem>::const_iterator i = _queue.begin(); i != _queue.end(); ++i) {
292                                         LOG_WARNING (N_("- type %1, size %2, frame %3, eyes %4"), i->type, i->size, i->frame, i->eyes);
293                                 }
294                                 LOG_WARNING (N_("Last written frame %1, last written eyes %2"), _last_written_frame, _last_written_eyes);
295                         }
296                         return;
297                 }
298                 /* Write any frames that we can write; i.e. those that are in sequence. */
299                 while (have_sequenced_image_at_queue_head ()) {
300                         done_something = true;
301                         QueueItem qi = _queue.front ();
302                         _queue.pop_front ();
303                         if (qi.type == QueueItem::FULL && qi.encoded) {
304                                 --_queued_full_in_memory;
305                         }
306
307                         lock.unlock ();
308                         switch (qi.type) {
309                         case QueueItem::FULL:
310                         {
311                                 LOG_GENERAL (N_("Writer FULL-writes %1 to MXF"), qi.frame);
312                                 if (!qi.encoded) {
313                                         qi.encoded.reset (new EncodedData (_film->j2c_path (qi.frame, qi.eyes, false)));
314                                 }
315
316                                 dcp::FrameInfo fin = _picture_mxf_writer->write (qi.encoded->data(), qi.encoded->size());
317                                 qi.encoded->write_info (_film, qi.frame, qi.eyes, fin);
318                                 _last_written[qi.eyes] = qi.encoded;
319                                 ++_full_written;
320                                 break;
321                         }
322                         case QueueItem::FAKE:
323                                 LOG_GENERAL (N_("Writer FAKE-writes %1 to MXF"), qi.frame);
324                                 _picture_mxf_writer->fake_write (qi.size);
325                                 _last_written[qi.eyes].reset ();
326                                 ++_fake_written;
327                                 break;
328                         }
329                         lock.lock ();
330
331                         _last_written_frame = qi.frame;
332                         _last_written_eyes = qi.eyes;
333                         
334                         shared_ptr<Job> job = _job.lock ();
335                         DCPOMATIC_ASSERT (job);
336                         int64_t total = _film->length().frames (_film->video_frame_rate ());
337                         if (_film->three_d ()) {
338                                 /* _full_written and so on are incremented for each eye, so we need to double the total
339                                    frames to get the correct progress.
340                                 */
341                                 total *= 2;
342                         }
343                         if (total) {
344                                 job->set_progress (float (_full_written + _fake_written) / total);
345                         }
346                 }
347
348                 while (_queued_full_in_memory > _maximum_frames_in_memory) {
349                         done_something = true;
350                         /* Too many frames in memory which can't yet be written to the stream.
351                            Write some FULL frames to disk.
352                         */
353
354                         /* Find one from the back of the queue */
355                         _queue.sort ();
356                         list<QueueItem>::reverse_iterator i = _queue.rbegin ();
357                         while (i != _queue.rend() && (i->type != QueueItem::FULL || !i->encoded)) {
358                                 ++i;
359                         }
360
361                         DCPOMATIC_ASSERT (i != _queue.rend());
362                         QueueItem qi = *i;
363
364                         ++_pushed_to_disk;
365                         
366                         lock.unlock ();
367
368                         LOG_GENERAL (
369                                 "Writer full (awaiting %1 [last eye was %2]); pushes %3 to disk",
370                                 _last_written_frame + 1,
371                                 _last_written_eyes, qi.frame
372                                 );
373                         
374                         qi.encoded->write (_film, qi.frame, qi.eyes);
375                         lock.lock ();
376                         qi.encoded.reset ();
377                         --_queued_full_in_memory;
378                 }
379
380                 if (!done_something) {
381                         LOG_DEBUG_NC ("Writer loop ran without doing anything");
382                         LOG_DEBUG ("_queued_full_in_memory=%1", _queued_full_in_memory);
383                         LOG_DEBUG ("_queue_size=%1", _queue.size ());
384                         LOG_DEBUG ("_finish=%1", _finish);
385                         LOG_DEBUG ("_last_written_frame=%1", _last_written_frame);
386                 }
387
388                 /* The queue has probably just gone down a bit; notify anything wait()ing on _full_condition */
389                 _full_condition.notify_all ();
390         }
391 }
392 catch (...)
393 {
394         store_current ();
395 }
396
397 void
398 Writer::terminate_thread (bool can_throw)
399 {
400         boost::mutex::scoped_lock lock (_mutex);
401         if (_thread == 0) {
402                 return;
403         }
404         
405         _finish = true;
406         _empty_condition.notify_all ();
407         _full_condition.notify_all ();
408         lock.unlock ();
409
410         _thread->join ();
411         if (can_throw) {
412                 rethrow ();
413         }
414         
415         delete _thread;
416         _thread = 0;
417 }       
418
419 void
420 Writer::finish ()
421 {
422         if (!_thread) {
423                 return;
424         }
425         
426         terminate_thread (true);
427
428         _picture_mxf_writer->finalize ();
429         if (_sound_mxf_writer) {
430                 _sound_mxf_writer->finalize ();
431         }
432         
433         /* Hard-link the video MXF into the DCP */
434         boost::filesystem::path video_from;
435         video_from /= _film->internal_video_mxf_dir();
436         video_from /= _film->internal_video_mxf_filename();
437         
438         boost::filesystem::path video_to;
439         video_to /= _film->dir (_film->dcp_name());
440         video_to /= _film->video_mxf_filename ();
441
442         boost::system::error_code ec;
443         boost::filesystem::create_hard_link (video_from, video_to, ec);
444         if (ec) {
445                 LOG_WARNING_NC ("Hard-link failed; copying instead");
446                 boost::filesystem::copy_file (video_from, video_to, ec);
447                 if (ec) {
448                         LOG_ERROR ("Failed to copy video file from %1 to %2 (%3)", video_from.string(), video_to.string(), ec.message ());
449                         throw FileError (ec.message(), video_from);
450                 }
451         }
452
453         _picture_mxf->set_file (video_to);
454
455         /* Move the audio MXF into the DCP */
456
457         if (_sound_mxf) {
458                 boost::filesystem::path audio_to;
459                 audio_to /= _film->dir (_film->dcp_name ());
460                 audio_to /= _film->audio_mxf_filename ();
461                 
462                 boost::filesystem::rename (_film->file (_film->audio_mxf_filename ()), audio_to, ec);
463                 if (ec) {
464                         throw FileError (
465                                 String::compose (_("could not move audio MXF into the DCP (%1)"), ec.value ()), _film->file (_film->audio_mxf_filename ())
466                                 );
467                 }
468
469                 _sound_mxf->set_file (audio_to);
470         }
471
472         dcp::DCP dcp (_film->dir (_film->dcp_name()));
473
474         shared_ptr<dcp::CPL> cpl (
475                 new dcp::CPL (
476                         _film->dcp_name(),
477                         _film->dcp_content_type()->libdcp_kind ()
478                         )
479                 );
480         
481         dcp.add (cpl);
482
483         shared_ptr<dcp::Reel> reel (new dcp::Reel ());
484
485         shared_ptr<dcp::MonoPictureMXF> mono = dynamic_pointer_cast<dcp::MonoPictureMXF> (_picture_mxf);
486         if (mono) {
487                 reel->add (shared_ptr<dcp::ReelPictureAsset> (new dcp::ReelMonoPictureAsset (mono, 0)));
488                 dcp.add (mono);
489         }
490
491         shared_ptr<dcp::StereoPictureMXF> stereo = dynamic_pointer_cast<dcp::StereoPictureMXF> (_picture_mxf);
492         if (stereo) {
493                 reel->add (shared_ptr<dcp::ReelPictureAsset> (new dcp::ReelStereoPictureAsset (stereo, 0)));
494                 dcp.add (stereo);
495         }
496
497         if (_sound_mxf) {
498                 reel->add (shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (_sound_mxf, 0)));
499                 dcp.add (_sound_mxf);
500         }
501
502         if (_subtitle_content) {
503                 _subtitle_content->write_xml (_film->dir (_film->dcp_name ()) / _film->subtitle_xml_filename ());
504                 reel->add (shared_ptr<dcp::ReelSubtitleAsset> (
505                                    new dcp::ReelSubtitleAsset (
506                                            _subtitle_content,
507                                            dcp::Fraction (_film->video_frame_rate(), 1),
508                                            _picture_mxf->intrinsic_duration (),
509                                            0
510                                            )
511                                    ));
512                 
513                 dcp.add (_subtitle_content);
514         }
515         
516         cpl->add (reel);
517
518         shared_ptr<Job> job = _job.lock ();
519         DCPOMATIC_ASSERT (job);
520
521         job->sub (_("Computing image digest"));
522         _picture_mxf->hash (boost::bind (&Job::set_progress, job.get(), _1, false));
523
524         if (_sound_mxf) {
525                 job->sub (_("Computing audio digest"));
526                 _sound_mxf->hash (boost::bind (&Job::set_progress, job.get(), _1, false));
527         }
528
529         dcp::XMLMetadata meta;
530         meta.issuer = Config::instance()->dcp_issuer ();
531         meta.creator = String::compose ("DCP-o-matic %1 %2", dcpomatic_version, dcpomatic_git_commit);
532         meta.set_issue_date_now ();
533
534         shared_ptr<const dcp::Signer> signer;
535         if (_film->is_signed ()) {
536                 signer = Config::instance()->signer ();
537                 /* We did check earlier, but check again here to be on the safe side */
538                 if (!signer->valid ()) {
539                         throw InvalidSignerError ();
540                 }
541         }
542
543         dcp.write_xml (_film->interop () ? dcp::INTEROP : dcp::SMPTE, meta, signer);
544
545         LOG_GENERAL (
546                 N_("Wrote %1 FULL, %2 FAKE, %3 pushed to disk"), _full_written, _fake_written, _pushed_to_disk
547                 );
548 }
549
550 bool
551 Writer::check_existing_picture_mxf_frame (FILE* mxf, int f, Eyes eyes)
552 {
553         /* Read the frame info as written */
554         FILE* ifi = fopen_boost (_film->info_path (f, eyes), "r");
555         if (!ifi) {
556                 LOG_GENERAL ("Existing frame %1 has no info file", f);
557                 return false;
558         }
559         
560         dcp::FrameInfo info (ifi);
561         fclose (ifi);
562         if (info.size == 0) {
563                 LOG_GENERAL ("Existing frame %1 has no info file", f);
564                 return false;
565         }
566         
567         /* Read the data from the MXF and hash it */
568         dcpomatic_fseek (mxf, info.offset, SEEK_SET);
569         EncodedData data (info.size);
570         size_t const read = fread (data.data(), 1, data.size(), mxf);
571         if (read != static_cast<size_t> (data.size ())) {
572                 LOG_GENERAL ("Existing frame %1 is incomplete", f);
573                 return false;
574         }
575
576         MD5Digester digester;
577         digester.add (data.data(), data.size());
578         if (digester.get() != info.hash) {
579                 LOG_GENERAL ("Existing frame %1 failed hash check", f);
580                 return false;
581         }
582
583         return true;
584 }
585
586 void
587 Writer::check_existing_picture_mxf ()
588 {
589         /* Try to open the existing MXF */
590         boost::filesystem::path p;
591         p /= _film->internal_video_mxf_dir ();
592         p /= _film->internal_video_mxf_filename ();
593         FILE* mxf = fopen_boost (p, "rb");
594         if (!mxf) {
595                 LOG_GENERAL ("Could not open existing MXF at %1 (errno=%2)", p.string(), errno);
596                 return;
597         }
598
599         int N = 0;
600         for (boost::filesystem::directory_iterator i (_film->info_dir ()); i != boost::filesystem::directory_iterator (); ++i) {
601                 ++N;
602         }
603
604         while (true) {
605
606                 shared_ptr<Job> job = _job.lock ();
607                 DCPOMATIC_ASSERT (job);
608
609                 if (N > 0) {
610                         job->set_progress (float (_first_nonexistant_frame) / N);
611                 }
612
613                 if (_film->three_d ()) {
614                         if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_LEFT)) {
615                                 break;
616                         }
617                         if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_RIGHT)) {
618                                 break;
619                         }
620                 } else {
621                         if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_BOTH)) {
622                                 break;
623                         }
624                 }
625
626                 LOG_GENERAL ("Have existing frame %1", _first_nonexistant_frame);
627                 ++_first_nonexistant_frame;
628         }
629
630         fclose (mxf);
631 }
632
633 /** @param frame Frame index.
634  *  @return true if we can fake-write this frame.
635  */
636 bool
637 Writer::can_fake_write (int frame) const
638 {
639         /* We have to do a proper write of the first frame so that we can set up the JPEG2000
640            parameters in the MXF writer.
641         */
642         return (frame != 0 && frame < _first_nonexistant_frame);
643 }
644
645 void
646 Writer::write (PlayerSubtitles subs)
647 {
648         if (subs.text.empty ()) {
649                 return;
650         }
651
652         if (!_subtitle_content) {
653                 _subtitle_content.reset (new dcp::InteropSubtitleContent (_film->name(), _film->subtitle_language ()));
654         }
655         
656         for (list<dcp::SubtitleString>::const_iterator i = subs.text.begin(); i != subs.text.end(); ++i) {
657                 _subtitle_content->add (*i);
658         }
659 }
660
661 void
662 Writer::write (list<shared_ptr<Font> > fonts)
663 {
664         if (fonts.empty ()) {
665                 return;
666         }
667         
668         if (!_subtitle_content) {
669                 _subtitle_content.reset (new dcp::InteropSubtitleContent (_film->name(), _film->subtitle_language ()));
670         }
671         
672         for (list<shared_ptr<Font> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
673                 /* XXX: this LiberationSans-Regular needs to be a path to a DCP-o-matic-distributed copy */
674                 _subtitle_content->add_font ((*i)->id, (*i)->file.get_value_or ("LiberationSans-Regular.ttf").leaf().string ());
675         }
676 }
677
678 bool
679 operator< (QueueItem const & a, QueueItem const & b)
680 {
681         if (a.frame != b.frame) {
682                 return a.frame < b.frame;
683         }
684
685         return static_cast<int> (a.eyes) < static_cast<int> (b.eyes);
686 }
687
688 bool
689 operator== (QueueItem const & a, QueueItem const & b)
690 {
691         return a.frame == b.frame && a.eyes == b.eyes;
692 }