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