More player debugging for butler video-full states.
[dcpomatic.git] / src / lib / writer.cc
index ea4a6d29beab4616dde6f4ff423b7b29d47ce050..45a74624f7da19564766b26ef2eba18da8f59b84 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -23,6 +23,7 @@
 #include "film.h"
 #include "ratio.h"
 #include "log.h"
+#include "dcpomatic_log.h"
 #include "dcp_video.h"
 #include "dcp_content_type.h"
 #include "audio_mapping.h"
 
 #include "i18n.h"
 
-#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
-#define LOG_GENERAL_NC(...) _film->log()->log (__VA_ARGS__, LogEntry::TYPE_GENERAL);
-#define LOG_DEBUG_ENCODE(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_DEBUG_ENCODE);
-#define LOG_TIMING(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_TIMING);
-#define LOG_WARNING_NC(...) _film->log()->log (__VA_ARGS__, LogEntry::TYPE_WARNING);
-#define LOG_WARNING(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_WARNING);
-#define LOG_ERROR(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_ERROR);
-
 /* OS X strikes again */
 #undef set_key
 
@@ -63,9 +56,11 @@ using std::cout;
 using std::map;
 using std::min;
 using std::max;
+using std::vector;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
+using boost::optional;
 using dcp::Data;
 
 Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
@@ -95,8 +90,9 @@ Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
           and captions arrive to the Writer in sequence.  This is not so for video.
        */
        _audio_reel = _reels.begin ();
-       for (int i = 0; i < TEXT_COUNT; ++i) {
-               _text_reel[i] = _reels.begin ();
+       _subtitle_reel = _reels.begin ();
+       BOOST_FOREACH (DCPTextTrack i, _film->closed_caption_tracks()) {
+               _caption_reels[i] = _reels.begin ();
        }
 
        /* Check that the signer is OK if we need one */
@@ -435,7 +431,7 @@ 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();
+                       int const awaiting = _reels[_queue.front().reel].last_written_video_frame() + 1;
                        lock.unlock ();
 
                        /* i is valid here, even though we don't hold a lock on the mutex,
@@ -638,7 +634,7 @@ Writer::write_cover_sheet ()
 
        boost::algorithm::replace_all (text, "$LENGTH", length);
 
-       fwrite (text.c_str(), 1, text.length(), f);
+       checked_fwrite (text.c_str(), text.length(), f, cover);
        fclose (f);
 }
 
@@ -664,17 +660,32 @@ Writer::can_fake_write (Frame frame) const
        return (frame != 0 && frame < reel.first_nonexistant_frame());
 }
 
+/** @param track Closed caption track if type == TEXT_CLOSED_CAPTION */
 void
-Writer::write (PlayerCaption text, TextType type, DCPTimePeriod period)
+Writer::write (PlayerText text, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period)
 {
-       while (_text_reel[type]->period().to <= period.from) {
-               ++_text_reel[type];
-               DCPOMATIC_ASSERT (_text_reel[type] != _reels.end());
+       vector<ReelWriter>::iterator* reel = 0;
+
+       switch (type) {
+       case TEXT_OPEN_SUBTITLE:
+               reel = &_subtitle_reel;
+               break;
+       case TEXT_CLOSED_CAPTION:
+               DCPOMATIC_ASSERT (track);
+               DCPOMATIC_ASSERT (_caption_reels.find(*track) != _caption_reels.end());
+               reel = &_caption_reels[*track];
+               break;
+       default:
+               DCPOMATIC_ASSERT (false);
        }
 
-       DCPOMATIC_ASSERT (_text_reel[type] != _reels.end());
+       DCPOMATIC_ASSERT (*reel != _reels.end());
+       while ((*reel)->period().to <= period.from) {
+               ++(*reel);
+               DCPOMATIC_ASSERT (*reel != _reels.end());
+       }
 
-       _text_reel[type]->write (text, type, period);
+       (*reel)->write (text, type, track, period);
 }
 
 void