Fix pull timing; fix units of ReelWriter::total_written_audio_frames.
[dcpomatic.git] / src / lib / writer.cc
index c0dbf0562631de24d2d5b1fdfbbc78aa340375a6..74e5e3ec081da7ded20a1da9946aa5cc3996b75e 100644 (file)
@@ -79,9 +79,6 @@ Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
        , _repeat_written (0)
        , _pushed_to_disk (0)
 {
-       /* Remove any old DCP */
-       boost::filesystem::remove_all (_film->dir (_film->dcp_name ()));
-
        shared_ptr<Job> job = _job.lock ();
        DCPOMATIC_ASSERT (job);
 
@@ -98,8 +95,9 @@ Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
        _subtitle_reel = _reels.begin ();
 
        /* Check that the signer is OK if we need one */
-       if (_film->is_signed() && !Config::instance()->signer_chain()->valid ()) {
-               throw InvalidSignerError ();
+       string reason;
+       if (_film->is_signed() && !Config::instance()->signer_chain()->valid(&reason)) {
+               throw InvalidSignerError (reason);
        }
 }
 
@@ -231,7 +229,7 @@ Writer::fake_write (Frame frame, Eyes eyes)
        _empty_condition.notify_all ();
 }
 
-/** Write one video frame's worth of audio frames to the DCP.
+/** Write some audio frames to the DCP.
  *  @param audio Audio data or 0 if there is no audio to be written here (i.e. it is referenced).
  *  This method is not thread safe.
  */
@@ -245,8 +243,7 @@ Writer::write (shared_ptr<const AudioBuffers> audio)
 
        _audio_reel->write (audio);
 
-       /* written is in video frames, not audio frames */
-       if (_audio_reel->total_written_audio_frames() >= _audio_reel->period().duration().frames_floor (_film->video_frame_rate())) {
+       if (_audio_reel->total_written_audio_frames() >= _audio_reel->period().duration().frames_floor (_film->audio_frame_rate())) {
                ++_audio_reel;
        }
 }
@@ -379,6 +376,8 @@ try
 
                        DCPOMATIC_ASSERT (i != _queue.rend());
                        ++_pushed_to_disk;
+                       /* For the log message below */
+                       int const awaiting = _reels[_queue.front().reel].last_written_video_frame();
                        lock.unlock ();
 
                        /* i is valid here, even though we don't hold a lock on the mutex,
@@ -386,7 +385,7 @@ try
                           thread could erase the last item in the list.
                        */
 
-                       LOG_GENERAL ("Writer full; pushes %1 to disk", i->frame);
+                       LOG_GENERAL ("Writer full; pushes %1 to disk while awaiting %2", i->frame, awaiting);
 
                        i->encoded->write_via_temp (
                                _film->j2c_path (i->reel, i->frame, i->eyes, true),
@@ -494,6 +493,7 @@ Writer::finish ()
        }
 
        dcp::XMLMetadata meta;
+       meta.annotation_text = cpl->annotation_text ();
        meta.creator = Config::instance()->dcp_creator ();
        if (meta.creator.empty ()) {
                meta.creator = String::compose ("DCP-o-matic %1 %2", dcpomatic_version, dcpomatic_git_commit);
@@ -510,8 +510,9 @@ Writer::finish ()
        if (_film->is_signed ()) {
                signer = Config::instance()->signer_chain ();
                /* We did check earlier, but check again here to be on the safe side */
-               if (!signer->valid ()) {
-                       throw InvalidSignerError ();
+               string reason;
+               if (!signer->valid (&reason)) {
+                       throw InvalidSignerError (reason);
                }
        }
 
@@ -540,13 +541,13 @@ Writer::can_fake_write (Frame frame) const
 }
 
 void
-Writer::write (PlayerSubtitles subs)
+Writer::write (PlayerSubtitles subs, DCPTimePeriod period)
 {
        if (subs.text.empty ()) {
                return;
        }
 
-       if (_subtitle_reel->period().to <= subs.from) {
+       if (_subtitle_reel->period().to <= period.from) {
                ++_subtitle_reel;
        }