2 Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 /** @file src/lib/writer.h
22 * @brief Writer class.
26 #include "player_text.h"
27 #include "exception_store.h"
28 #include "dcp_text_track.h"
29 #include <boost/shared_ptr.hpp>
30 #include <boost/weak_ptr.hpp>
31 #include <boost/thread.hpp>
32 #include <boost/thread/condition.hpp>
46 class ReferencedReelAsset;
60 /** a normal frame with some JPEG200 data */
62 /** a frame whose data already exists in the MXF,
63 and we fake-write it; i.e. we update the writer's
64 state but we use the data that is already on disk.
70 /** encoded data for FULL */
71 boost::optional<dcp::Data> encoded;
72 /** size of data for FAKE */
76 /** frame index within the reel */
78 /** eyes for FULL, FAKE and REPEAT */
82 bool operator< (QueueItem const & a, QueueItem const & b);
83 bool operator== (QueueItem const & a, QueueItem const & b);
86 * @brief Class to manage writing JPEG2000 and audio data to assets on disk.
88 * This class creates sound and picture assets, then takes Data
89 * or AudioBuffers objects (containing image or sound data respectively)
90 * and writes them to the assets.
92 * write() for Data (picture) can be called out of order, and the Writer
93 * will sort it out. write() for AudioBuffers must be called in order.
96 class Writer : public ExceptionStore, public boost::noncopyable
99 Writer (boost::shared_ptr<const Film>, boost::weak_ptr<Job>);
104 bool can_fake_write (Frame) const;
106 void write (dcp::Data, Frame, Eyes);
107 void fake_write (Frame, Eyes);
108 bool can_repeat (Frame) const;
109 void repeat (Frame, Eyes);
110 void write (boost::shared_ptr<const AudioBuffers>, dcpomatic::DCPTime time);
111 void write (PlayerText text, TextType type, boost::optional<DCPTextTrack>, dcpomatic::DCPTimePeriod period);
112 void write (std::list<boost::shared_ptr<dcpomatic::Font> > fonts);
113 void write (ReferencedReelAsset asset);
116 void set_encoder_threads (int threads);
120 void terminate_thread (bool);
121 bool have_sequenced_image_at_queue_head ();
122 size_t video_reel (int frame) const;
123 void set_digest_progress (Job* job, float progress);
124 void write_cover_sheet ();
127 boost::shared_ptr<const Film> _film;
128 boost::weak_ptr<Job> _job;
129 std::vector<ReelWriter> _reels;
130 std::vector<ReelWriter>::iterator _audio_reel;
131 std::vector<ReelWriter>::iterator _subtitle_reel;
132 std::map<DCPTextTrack, std::vector<ReelWriter>::iterator> _caption_reels;
134 /** our thread, or 0 */
135 boost::thread* _thread;
136 /** true if our thread should finish */
138 /** queue of things to write to disk */
139 std::list<QueueItem> _queue;
140 /** number of FULL frames whose JPEG200 data is currently held in RAM */
141 int _queued_full_in_memory;
142 /** mutex for thread state */
143 mutable boost::mutex _state_mutex;
144 /** condition to manage thread wakeups when we have nothing to do */
145 boost::condition _empty_condition;
146 /** condition to manage thread wakeups when we have too much to do */
147 boost::condition _full_condition;
148 /** maximum number of frames to hold in memory, for when we are managing
151 int _maximum_frames_in_memory;
152 unsigned int _maximum_queue_size;
154 /** number of FULL written frames */
156 /** number of FAKE written frames */
159 /** number of frames pushed to disk and then recovered
160 due to the limit of frames to be held in memory.
164 boost::mutex _digest_progresses_mutex;
165 std::map<boost::thread::id, float> _digest_progresses;
167 std::list<ReferencedReelAsset> _reel_assets;
169 std::list<boost::shared_ptr<dcpomatic::Font> > _fonts;