Add minimal player HTTP server (#2830).
[dcpomatic.git] / src / lib / writer.h
index aab7d5fc78da6e1d5c4211093c34c04b2781d2ea..3e93c9b7b56f4c5e9c8d293982dea52951cd2008 100644 (file)
 */
 
 
+#ifndef DCPOMATIC_WRITER_H
+#define DCPOMATIC_WRITER_H
+
+
 /** @file  src/lib/writer.h
  *  @brief Writer class.
  */
 
 
 #include "atmos_metadata.h"
-#include "types.h"
-#include "player_text.h"
-#include "exception_store.h"
 #include "dcp_text_track.h"
+#include "dcpomatic_time.h"
+#include "exception_store.h"
+#include "font_id_map.h"
+#include "player_text.h"
+#include "text_type.h"
+#include "types.h"
 #include "weak_film.h"
 #include <dcp/atmos_frame.h>
+#include <dcp/frame_info.h>
+#include <dcp/mono_mpeg2_picture_frame.h>
 #include <boost/thread.hpp>
 #include <boost/thread/condition.hpp>
 #include <list>
@@ -40,15 +49,14 @@ namespace dcp {
        class Data;
 }
 
-namespace dcpomatic {
-       class FontData;
-}
-
-class Film;
 class AudioBuffers;
+class Film;
 class Job;
-class ReferencedReelAsset;
 class ReelWriter;
+class ReferencedReelAsset;
+struct writer_disambiguate_font_ids1;
+struct writer_disambiguate_font_ids2;
+struct writer_disambiguate_font_ids3;
 
 
 struct QueueItem
@@ -69,8 +77,8 @@ public:
 
        /** encoded data for FULL */
        std::shared_ptr<const dcp::Data> encoded;
-       /** size of data for FAKE */
-       int size = 0;
+       /** info for FAKE */
+       dcp::J2KFrameInfo info;
        /** reel index */
        size_t reel = 0;
        /** frame index within the reel */
@@ -98,7 +106,7 @@ bool operator== (QueueItem const & a, QueueItem const & b);
 class Writer : public ExceptionStore, public WeakConstFilm
 {
 public:
-       Writer (std::weak_ptr<const Film>, std::weak_ptr<Job>, bool text_only = false);
+       Writer(std::weak_ptr<const Film>, std::weak_ptr<Job>, boost::filesystem::path output_dir, bool text_only = false);
        ~Writer ();
 
        Writer (Writer const &) = delete;
@@ -114,22 +122,30 @@ public:
        void repeat (Frame, Eyes);
        void write (std::shared_ptr<const AudioBuffers>, dcpomatic::DCPTime time);
        void write (PlayerText text, TextType type, boost::optional<DCPTextTrack>, dcpomatic::DCPTimePeriod period);
-       void write (std::vector<dcpomatic::FontData> fonts);
+       void write (std::vector<std::shared_ptr<dcpomatic::Font>> fonts);
        void write (ReferencedReelAsset asset);
        void write (std::shared_ptr<const dcp::AtmosFrame> atmos, dcpomatic::DCPTime time, AtmosMetadata metadata);
-       void finish (boost::filesystem::path output_dcp);
+       void write (std::shared_ptr<dcp::MonoMPEG2PictureFrame> image, Frame frame);
+       void finish();
 
        void set_encoder_threads (int threads);
 
+       void zombify();
+
 private:
+       friend struct ::writer_disambiguate_font_ids1;
+       friend struct ::writer_disambiguate_font_ids2;
+       friend struct ::writer_disambiguate_font_ids3;
+
        void thread ();
        void terminate_thread (bool);
        bool have_sequenced_image_at_queue_head ();
        size_t video_reel (int frame) const;
-       void set_digest_progress (Job* job, float progress);
-       void write_cover_sheet (boost::filesystem::path output_dcp);
-       void calculate_referenced_digests (boost::function<void (float)> set_progress);
+       void set_digest_progress(Job* job, int id, int64_t done, int64_t size);
+       void write_cover_sheet();
+       void calculate_referenced_digests(std::function<void (int64_t, int64_t)> set_progress);
        void write_hanging_text (ReelWriter& reel);
+       void calculate_digests ();
 
        std::weak_ptr<Job> _job;
        std::vector<ReelWriter> _reels;
@@ -138,6 +154,7 @@ private:
        std::map<DCPTextTrack, std::vector<ReelWriter>::iterator> _caption_reels;
        std::vector<ReelWriter>::iterator _atmos_reel;
 
+       boost::filesystem::path _output_dir;
        /** our thread */
        boost::thread _thread;
        /** true if our thread should finish */
@@ -195,11 +212,15 @@ private:
        bool _text_only;
 
        boost::mutex _digest_progresses_mutex;
-       std::map<boost::thread::id, float> _digest_progresses;
+       std::map<int, std::pair<int64_t, int64_t>> _digest_progresses;
 
        std::list<ReferencedReelAsset> _reel_assets;
 
-       std::vector<dcpomatic::FontData> _fonts;
+       FontIdMap _fonts;
+       /** If we are given many fonts, but we're making an Interop DCP, we'll choose a single
+        *  one that we'll use everywher.  This is that chosen font.
+        */
+       std::shared_ptr<dcpomatic::Font> _chosen_interop_font;
 
        /** true if any reel has any subtitles */
        bool _have_subtitles = false;
@@ -214,4 +235,10 @@ private:
        };
 
        std::vector<HangingText> _hanging_texts;
+
+       bool _zombie = false;
 };
+
+
+#endif
+