wip: allow multi-content pieces.
[dcpomatic.git] / src / lib / piece.h
1 /*
2     Copyright (C) 2013-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 #ifndef DCPOMATIC_PIECE_H
22 #define DCPOMATIC_PIECE_H
23
24
25 #include "audio_stream.h"
26 #include "colour_conversion.h"
27 #include "content_atmos.h"
28 #include "content_audio.h"
29 #include "content_text.h"
30 #include "content_video.h"
31 #include "font.h"
32 #include "dcpomatic_time.h"
33 #include "frame_rate_change.h"
34 #include "types.h"
35
36
37 class Content;
38 class Decoder;
39 struct check_reuse_old_data_test;
40
41
42 class Piece
43 {
44 public:
45         Piece (
46                 boost::shared_ptr<const Film> film,
47                 ContentList content,
48                 bool fast,
49                 bool tolerant,
50                 bool ignore_video,
51                 bool ignore_audio,
52                 bool ignore_text,
53                 bool play_referenced,
54                 boost::optional<int> dcp_decode_reduction
55               );
56
57         Piece (boost::shared_ptr<Content> c, boost::shared_ptr<Decoder> d, FrameRateChange f);
58
59         void update_pull_to (dcpomatic::DCPTime& pull_to) const;
60         void set_last_push_end (AudioStreamPtr stream, dcpomatic::DCPTime last_push_end);
61         boost::optional<dcpomatic::DCPTime> decoder_position (boost::shared_ptr<const Film> film);
62         bool has_text () const;
63         bool reference_audio () const;
64
65         void pass ();
66         void seek (boost::shared_ptr<const Film> film, dcpomatic::DCPTime time, bool accurate);
67
68         dcpomatic::DCPTime position () const;
69         dcpomatic::DCPTime end (boost::shared_ptr<const Film> film) const;
70         FrameRateChange frame_rate_change () const {
71                 return _frc;
72         }
73
74         bool video_use () const;
75         Crop video_crop () const;
76         boost::optional<double> video_fade (boost::shared_ptr<const Film> film, Frame) const;
77         boost::optional<ColourConversion> video_colour_conversion () const;
78         VideoRange video_range () const;
79         dcp::Size video_scaled_size (dcp::Size container_size) const;
80
81         int audio_resampled_frame_rate (boost::shared_ptr<const Film> film) const;
82         double audio_gain () const;
83
84         dcpomatic::DCPTime content_video_to_dcp (Frame f) const;
85         dcpomatic::DCPTime resampled_audio_to_dcp (boost::shared_ptr<const Film> film, Frame f) const;
86         dcpomatic::ContentTime dcp_to_content_time (boost::shared_ptr<const Film> film, dcpomatic::DCPTime t) const;
87         dcpomatic::DCPTime content_time_to_dcp (dcpomatic::ContentTime t) const;
88         boost::optional<dcpomatic::DCPTime> content_time_to_dcp (boost::shared_ptr<Content> content, dcpomatic::ContentTime t) const;
89
90         void add_fonts (std::list<boost::shared_ptr<dcpomatic::Font> >& fonts) const;
91
92         boost::signals2::signal<void (ContentVideo)> Video;
93         boost::signals2::signal<void (AudioStreamPtr, ContentAudio)> Audio;
94         boost::signals2::signal<void (boost::weak_ptr<const TextContent>, ContentBitmapText)> BitmapTextStart;
95         boost::signals2::signal<void (boost::weak_ptr<const TextContent>, ContentStringText)> PlainTextStart;
96         boost::signals2::signal<void (boost::weak_ptr<const TextContent>, dcpomatic::ContentTime)> TextStop;
97         boost::signals2::signal<void (ContentAtmos)> Atmos;
98
99 private:
100         friend struct ::check_reuse_old_data_test;
101
102         std::vector<boost::shared_ptr<Content> > _content;
103         std::vector<boost::shared_ptr<Decoder> > _decoder;
104         FrameRateChange _frc;
105         bool _done;
106
107         std::map<AudioStreamPtr, dcpomatic::DCPTime> _stream_last_push_end;
108 };
109
110 #endif