Temporary hack to double-check existing frame hashes.
[dcpomatic.git] / src / lib / reel_writer.h
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "types.h"
21 #include "dcpomatic_time.h"
22 #include "referenced_reel_asset.h"
23 #include "player_subtitles.h"
24 #include <dcp/picture_asset_writer.h>
25 #include <boost/shared_ptr.hpp>
26
27 class Film;
28 class Job;
29 class Font;
30 class AudioBuffers;
31
32 namespace dcp {
33         class MonoPictureAsset;
34         class MonoPictureAssetWriter;
35         class StereoPictureAsset;
36         class StereoPictureAssetWriter;
37         class PictureAsset;
38         class PictureAssetWriter;
39         class SoundAsset;
40         class SoundAssetWriter;
41         class SubtitleAsset;
42         class ReelAsset;
43         class Reel;
44 }
45
46 class ReelWriter
47 {
48 public:
49         ReelWriter (boost::shared_ptr<const Film> film, DCPTimePeriod period, boost::shared_ptr<Job> job);
50
51         void write (boost::optional<dcp::Data> encoded, Frame frame, Eyes eyes);
52         void fake_write (Frame frame, Eyes eyes, int size);
53         void repeat_write (Frame frame, Eyes eyes);
54         void write (boost::shared_ptr<const AudioBuffers> audio);
55         void write (PlayerSubtitles subs);
56
57         void finish ();
58         boost::shared_ptr<dcp::Reel> create_reel (std::list<ReferencedReelAsset> const & refs, std::list<boost::shared_ptr<Font> > const & fonts);
59         void calculate_digests (boost::shared_ptr<Job> job);
60
61         Frame start () const;
62
63         DCPTimePeriod period () const {
64                 return _period;
65         }
66
67         int total_written_audio_frames () const {
68                 return _total_written_audio_frames;
69         }
70
71         int last_written_video_frame () const {
72                 return _last_written_video_frame;
73         }
74
75         Eyes last_written_eyes () const {
76                 return _last_written_eyes;
77         }
78
79         int first_nonexistant_frame () const {
80                 return _first_nonexistant_frame;
81         }
82
83         dcp::FrameInfo read_frame_info (FILE* file, Frame frame, Eyes eyes) const;
84
85 private:
86
87         void write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const;
88         long frame_info_position (Frame frame, Eyes eyes) const;
89         void check_existing_picture_asset ();
90         bool existing_picture_frame_ok (FILE* asset_file, FILE* info_file, int frame) const;
91
92         boost::shared_ptr<const Film> _film;
93
94         DCPTimePeriod _period;
95         /** the first frame index that does not already exist in our MXF */
96         int _first_nonexistant_frame;
97         /** the data of the last written frame, if there is one */
98         boost::optional<dcp::Data> _last_written[EYES_COUNT];
99         /** the index of the last written video frame within the reel */
100         int _last_written_video_frame;
101         Eyes _last_written_eyes;
102         /** the number of audio frames that have been written to the reel */
103         int _total_written_audio_frames;
104
105         boost::shared_ptr<dcp::PictureAsset> _picture_asset;
106         boost::shared_ptr<dcp::PictureAssetWriter> _picture_asset_writer;
107         boost::shared_ptr<dcp::SoundAsset> _sound_asset;
108         boost::shared_ptr<dcp::SoundAssetWriter> _sound_asset_writer;
109         boost::shared_ptr<dcp::SubtitleAsset> _subtitle_asset;
110
111         static int const _info_size;
112 };