2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "audio_content.h"
26 #include "player_video.h"
27 #include "video_content.h"
30 using std::shared_ptr;
31 using std::make_shared;
32 using namespace dcpomatic;
35 Piece::Piece (shared_ptr<Content> c, shared_ptr<Decoder> d, FrameRateChange f)
41 for (auto j: content->audio->streams()) {
42 _stream_last_push_end[j] = content->position();
50 Piece::update_pull_to (DCPTime& pull_to) const
56 for (auto const& i: _stream_last_push_end) {
57 pull_to = std::min(pull_to, i.second);
63 Piece::set_last_push_end (AudioStreamPtr stream, DCPTime end)
65 DCPOMATIC_ASSERT (_stream_last_push_end.find(stream) != _stream_last_push_end.end());
66 _stream_last_push_end[stream] = end;
71 Piece::content_video_to_dcp (Frame f) const
73 /* See comment in resampled_audio_to_dcp */
74 auto const d = DCPTime::from_frames(f * frc.factor(), frc.dcp) - DCPTime(content->trim_start(), frc);
75 return d + content->position();
80 Piece::resampled_audio_to_dcp (Frame f, shared_ptr<const Film> film) const
82 /* It might seem more logical here to convert s to a ContentTime (using the FrameRateChange)
83 then convert that ContentTime to frames at the content's rate. However this fails for
84 situations like content at 29.9978733fps, DCP at 30fps. The accuracy of the Time type is not
85 enough to distinguish between the two with low values of time (e.g. 3200 in Time units).
87 Instead we convert the DCPTime using the DCP video rate then account for any skip/repeat.
89 return DCPTime::from_frames(f, film->audio_frame_rate())
90 - DCPTime(content->trim_start(), frc)
91 + content->position();
96 Piece::dcp_to_content_time (DCPTime t, shared_ptr<const Film> film) const
98 auto s = t - content->position ();
99 s = min (content->length_after_trim(film), s);
100 return max (ContentTime(), ContentTime(s, frc) + content->trim_start());
105 Piece::content_time_to_dcp (ContentTime t) const
107 return max (DCPTime(), DCPTime(t - content->trim_start(), frc) + content->position());
112 Piece::use_video () const
114 return content->video && content->video->use();
119 Piece::position () const
121 return content->position ();
126 Piece::end (shared_ptr<const Film> film) const
128 return content->end (film);
132 shared_ptr<PlayerVideo>
133 Piece::player_video (ContentVideo video, shared_ptr<const Film> film, dcp::Size container_size) const
135 return std::make_shared<PlayerVideo>(
137 content->video->crop (),
138 content->video->fade (film, video.frame),
139 scale_for_display(content->video->scaled_size(film->frame_size()), container_size, film->frame_size()),
143 content->video->colour_conversion(),
144 content->video->range(),
153 Piece::resampled_audio_frame_rate (shared_ptr<const Film> film) const
155 DCPOMATIC_ASSERT (content->audio);
156 return content->audio->resampled_frame_rate (film);