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