Tidying.
[dcpomatic.git] / src / lib / reel_writer.h
1 /*
2     Copyright (C) 2012-2020 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
22 #include "atmos_metadata.h"
23 #include "dcp_text_track.h"
24 #include "dcpomatic_time.h"
25 #include "player_text.h"
26 #include "referenced_reel_asset.h"
27 #include "types.h"
28 #include "weak_film.h"
29 #include <dcp/atmos_asset_writer.h>
30 #include <dcp/file.h>
31 #include <dcp/picture_asset_writer.h>
32
33
34 namespace dcpomatic {
35         class FontData;
36 }
37
38 class AudioBuffers;
39 class Film;
40 class InfoFileHandle;
41 class Job;
42 struct write_frame_info_test;
43
44 namespace dcp {
45         class AtmosAsset;
46         class MonoPictureAsset;
47         class MonoPictureAssetWriter;
48         class PictureAsset;
49         class PictureAssetWriter;
50         class Reel;
51         class ReelAsset;
52         class ReelPictureAsset;
53         class SoundAsset;
54         class SoundAssetWriter;
55         class StereoPictureAsset;
56         class StereoPictureAssetWriter;
57         class SubtitleAsset;
58 }
59
60
61 class ReelWriter : public WeakConstFilm
62 {
63 public:
64         ReelWriter (
65                 std::weak_ptr<const Film> film,
66                 dcpomatic::DCPTimePeriod period,
67                 std::shared_ptr<Job> job,
68                 int reel_index,
69                 int reel_count,
70                 bool text_only
71                 );
72
73         void write (std::shared_ptr<const dcp::Data> encoded, Frame frame, Eyes eyes);
74         void fake_write (int size);
75         void repeat_write (Frame frame, Eyes eyes);
76         void write (std::shared_ptr<const AudioBuffers> audio);
77         void write (PlayerText text, TextType type, boost::optional<DCPTextTrack> track, dcpomatic::DCPTimePeriod period);
78         void write (std::shared_ptr<const dcp::AtmosFrame> atmos, AtmosMetadata metadata);
79
80         void finish (boost::filesystem::path output_dcp);
81         std::shared_ptr<dcp::Reel> create_reel (
82                 std::list<ReferencedReelAsset> const & refs,
83                 std::vector<dcpomatic::FontData> const & fonts,
84                 boost::filesystem::path output_dcp,
85                 bool ensure_subtitles,
86                 std::set<DCPTextTrack> ensure_closed_captions
87                 );
88         void calculate_digests (std::function<void (float)> set_progress);
89
90         Frame start () const;
91
92         dcpomatic::DCPTimePeriod period () const {
93                 return _period;
94         }
95
96         int first_nonexistant_frame () const {
97                 return _first_nonexistant_frame;
98         }
99
100         dcp::FrameInfo read_frame_info (std::shared_ptr<InfoFileHandle> info, Frame frame, Eyes eyes) const;
101
102 private:
103
104         friend struct ::write_frame_info_test;
105
106         void write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const;
107         long frame_info_position (Frame frame, Eyes eyes) const;
108         Frame check_existing_picture_asset (boost::filesystem::path asset);
109         bool existing_picture_frame_ok (dcp::File& asset_file, std::shared_ptr<InfoFileHandle> info_file, Frame frame) const;
110         std::shared_ptr<dcp::SubtitleAsset> empty_text_asset (TextType type, boost::optional<DCPTextTrack> track, bool with_dummy) const;
111
112         std::shared_ptr<dcp::ReelPictureAsset> create_reel_picture (std::shared_ptr<dcp::Reel> reel, std::list<ReferencedReelAsset> const & refs) const;
113         void create_reel_sound (std::shared_ptr<dcp::Reel> reel, std::list<ReferencedReelAsset> const & refs) const;
114         void create_reel_text (
115                 std::shared_ptr<dcp::Reel> reel,
116                 std::list<ReferencedReelAsset> const & refs,
117                 std::vector<dcpomatic::FontData> const& fonts,
118                 int64_t duration,
119                 boost::filesystem::path output_dcp,
120                 bool ensure_subtitles,
121                 std::set<DCPTextTrack> ensure_closed_captions
122                 ) const;
123         void create_reel_markers (std::shared_ptr<dcp::Reel> reel) const;
124
125         dcpomatic::DCPTimePeriod _period;
126         /** the first picture frame index that does not already exist in our MXF */
127         int _first_nonexistant_frame;
128         /** the data of the last written frame, if there is one */
129         std::shared_ptr<const dcp::Data> _last_written[static_cast<int>(Eyes::COUNT)];
130         /** index of this reel within the DCP (starting from 0) */
131         int _reel_index;
132         /** number of reels in the DCP */
133         int _reel_count;
134         boost::optional<std::string> _content_summary;
135         std::weak_ptr<Job> _job;
136         bool _text_only;
137
138         dcp::ArrayData _default_font;
139
140         std::shared_ptr<dcp::PictureAsset> _picture_asset;
141         /** picture asset writer, or 0 if we are not writing any picture because we already have one */
142         std::shared_ptr<dcp::PictureAssetWriter> _picture_asset_writer;
143         std::shared_ptr<dcp::SoundAsset> _sound_asset;
144         std::shared_ptr<dcp::SoundAssetWriter> _sound_asset_writer;
145         std::shared_ptr<dcp::SubtitleAsset> _subtitle_asset;
146         std::map<DCPTextTrack, std::shared_ptr<dcp::SubtitleAsset>> _closed_caption_assets;
147         std::shared_ptr<dcp::AtmosAsset> _atmos_asset;
148         std::shared_ptr<dcp::AtmosAssetWriter> _atmos_asset_writer;
149
150         static int const _info_size;
151 };