Another macOS std::list boost::thread SNAFU.
[dcpomatic.git] / src / lib / reel_writer.h
1 /*
2     Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "types.h"
22 #include "dcpomatic_time.h"
23 #include "referenced_reel_asset.h"
24 #include "player_text.h"
25 #include "dcp_text_track.h"
26 #include <dcp/picture_asset_writer.h>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/weak_ptr.hpp>
29
30 namespace dcpomatic {
31         class Font;
32 }
33
34 class Film;
35 class Job;
36 class AudioBuffers;
37 class InfoFileHandle;
38 struct write_frame_info_test;
39
40 namespace dcp {
41         class MonoPictureAsset;
42         class MonoPictureAssetWriter;
43         class StereoPictureAsset;
44         class StereoPictureAssetWriter;
45         class PictureAsset;
46         class PictureAssetWriter;
47         class SoundAsset;
48         class SoundAssetWriter;
49         class SubtitleAsset;
50         class ReelAsset;
51         class Reel;
52 }
53
54 class ReelWriter
55 {
56 public:
57         ReelWriter (
58                 boost::shared_ptr<const Film> film,
59                 dcpomatic::DCPTimePeriod period,
60                 boost::shared_ptr<Job> job,
61                 int reel_index,
62                 int reel_count,
63                 boost::optional<std::string> content_summary
64                 );
65
66         void write (boost::optional<dcp::Data> encoded, Frame frame, Eyes eyes);
67         void fake_write (Frame frame, Eyes eyes, int size);
68         void repeat_write (Frame frame, Eyes eyes);
69         void write (boost::shared_ptr<const AudioBuffers> audio);
70         void write (PlayerText text, TextType type, boost::optional<DCPTextTrack> track, dcpomatic::DCPTimePeriod period);
71
72         void finish ();
73         boost::shared_ptr<dcp::Reel> create_reel (std::list<ReferencedReelAsset> const & refs, std::list<boost::shared_ptr<dcpomatic::Font> > const & fonts);
74         void calculate_digests (boost::function<void (float)> set_progress);
75
76         Frame start () const;
77
78         dcpomatic::DCPTimePeriod period () const {
79                 return _period;
80         }
81
82         int last_written_video_frame () const {
83                 return _last_written_video_frame;
84         }
85
86         Eyes last_written_eyes () const {
87                 return _last_written_eyes;
88         }
89
90         int first_nonexistant_frame () const {
91                 return _first_nonexistant_frame;
92         }
93
94         dcp::FrameInfo read_frame_info (boost::shared_ptr<InfoFileHandle> info, Frame frame, Eyes eyes) const;
95
96 private:
97
98         friend struct ::write_frame_info_test;
99
100         void write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const;
101         long frame_info_position (Frame frame, Eyes eyes) const;
102         Frame check_existing_picture_asset (boost::filesystem::path asset);
103         bool existing_picture_frame_ok (FILE* asset_file, boost::shared_ptr<InfoFileHandle> info_file, Frame frame) const;
104
105         boost::shared_ptr<const Film> _film;
106
107         dcpomatic::DCPTimePeriod _period;
108         /** the first picture frame index that does not already exist in our MXF */
109         int _first_nonexistant_frame;
110         /** the data of the last written frame, if there is one */
111         boost::optional<dcp::Data> _last_written[EYES_COUNT];
112         /** the index of the last written video frame within the reel */
113         int _last_written_video_frame;
114         Eyes _last_written_eyes;
115         /** index of this reel within the DCP (starting from 0) */
116         int _reel_index;
117         /** number of reels in the DCP */
118         int _reel_count;
119         boost::optional<std::string> _content_summary;
120         boost::weak_ptr<Job> _job;
121
122         boost::shared_ptr<dcp::PictureAsset> _picture_asset;
123         /** picture asset writer, or 0 if we are not writing any picture because we already have one */
124         boost::shared_ptr<dcp::PictureAssetWriter> _picture_asset_writer;
125         boost::shared_ptr<dcp::SoundAsset> _sound_asset;
126         boost::shared_ptr<dcp::SoundAssetWriter> _sound_asset_writer;
127         boost::shared_ptr<dcp::SubtitleAsset> _subtitle_asset;
128         std::map<DCPTextTrack, boost::shared_ptr<dcp::SubtitleAsset> > _closed_caption_assets;
129
130         static int const _info_size;
131 };