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