fff2e0b9ea7568d646b4ef0b18b86e5104757799
[dcpomatic.git] / src / lib / reel_writer.h
1 /*
2     Copyright (C) 2012-2018 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
29 namespace dcpomatic {
30         class Font;
31 }
32
33 class Film;
34 class Job;
35 class AudioBuffers;
36
37 namespace dcp {
38         class MonoPictureAsset;
39         class MonoPictureAssetWriter;
40         class StereoPictureAsset;
41         class StereoPictureAssetWriter;
42         class PictureAsset;
43         class PictureAssetWriter;
44         class SoundAsset;
45         class SoundAssetWriter;
46         class SubtitleAsset;
47         class ReelAsset;
48         class Reel;
49 }
50
51 class ReelWriter
52 {
53 public:
54         ReelWriter (
55                 boost::shared_ptr<const Film> film,
56                 dcpomatic::DCPTimePeriod period,
57                 boost::shared_ptr<Job> job,
58                 int reel_index,
59                 int reel_count,
60                 boost::optional<std::string> content_summary
61                 );
62
63         void write (boost::optional<dcp::Data> encoded, Frame frame, Eyes eyes);
64         void fake_write (Frame frame, Eyes eyes, int size);
65         void repeat_write (Frame frame, Eyes eyes);
66         void write (boost::shared_ptr<const AudioBuffers> audio);
67         void write (PlayerText text, TextType type, boost::optional<DCPTextTrack> track, dcpomatic::DCPTimePeriod period);
68
69         void finish ();
70         boost::shared_ptr<dcp::Reel> create_reel (std::list<ReferencedReelAsset> const & refs, std::list<boost::shared_ptr<dcpomatic::Font> > const & fonts);
71         void calculate_digests (boost::function<void (float)> set_progress);
72
73         Frame start () const;
74
75         dcpomatic::DCPTimePeriod period () const {
76                 return _period;
77         }
78
79         int last_written_video_frame () const {
80                 return _last_written_video_frame;
81         }
82
83         Eyes last_written_eyes () const {
84                 return _last_written_eyes;
85         }
86
87         int first_nonexistant_frame () const {
88                 return _first_nonexistant_frame;
89         }
90
91         dcp::FrameInfo read_frame_info (FILE* file, Frame frame, Eyes eyes) const;
92
93 private:
94
95         void write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const;
96         long frame_info_position (Frame frame, Eyes eyes) const;
97         Frame check_existing_picture_asset ();
98         bool existing_picture_frame_ok (FILE* asset_file, FILE* info_file, Frame frame) const;
99
100         boost::shared_ptr<const Film> _film;
101
102         dcpomatic::DCPTimePeriod _period;
103         /** the first picture frame index that does not already exist in our MXF */
104         int _first_nonexistant_frame;
105         /** the data of the last written frame, if there is one */
106         boost::optional<dcp::Data> _last_written[EYES_COUNT];
107         /** the index of the last written video frame within the reel */
108         int _last_written_video_frame;
109         Eyes _last_written_eyes;
110         /** index of this reel within the DCP (starting from 0) */
111         int _reel_index;
112         /** number of reels in the DCP */
113         int _reel_count;
114         boost::optional<std::string> _content_summary;
115
116         boost::shared_ptr<dcp::PictureAsset> _picture_asset;
117         boost::shared_ptr<dcp::PictureAssetWriter> _picture_asset_writer;
118         boost::shared_ptr<dcp::SoundAsset> _sound_asset;
119         boost::shared_ptr<dcp::SoundAssetWriter> _sound_asset_writer;
120         boost::shared_ptr<dcp::SubtitleAsset> _subtitle_asset;
121         std::map<DCPTextTrack, boost::shared_ptr<dcp::SubtitleAsset> > _closed_caption_assets;
122
123         static int const _info_size;
124 };