diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-06-24 00:26:43 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-12-01 16:43:36 +0100 |
| commit | b82caf0bab5aad9fbb952488d868491d26163bd7 (patch) | |
| tree | 2eb0c37362e72050f396c2718de1701caa907cf5 /src/lib | |
| parent | 908646bb5753833a652424babb3f1f3f3018d0f4 (diff) | |
More function moves and build fixes; now builds.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/piece.cc | 100 | ||||
| -rw-r--r-- | src/lib/piece.h | 19 | ||||
| -rw-r--r-- | src/lib/player.cc | 50 | ||||
| -rw-r--r-- | src/lib/player_video.cc | 23 | ||||
| -rw-r--r-- | src/lib/player_video.h | 12 |
5 files changed, 149 insertions, 55 deletions
diff --git a/src/lib/piece.cc b/src/lib/piece.cc index 9fcf40834..879bf71c5 100644 --- a/src/lib/piece.cc +++ b/src/lib/piece.cc @@ -19,15 +19,24 @@ */ +#include "audio_content.h" #include "audio_stream.h" #include "content.h" +#include "dcp_content.h" +#include "decoder.h" #include "piece.h" +#include "text_content.h" +#include "video_content.h" #include <boost/foreach.hpp> using std::copy; using std::list; +using std::map; +using boost::dynamic_pointer_cast; +using boost::optional; using boost::shared_ptr; +using namespace dcpomatic; Piece::Piece (shared_ptr<Content> c, shared_ptr<Decoder> d, FrameRateChange f) @@ -102,7 +111,7 @@ DCPTime Piece::resampled_audio_to_dcp (shared_ptr<const Film> film, Frame f) const { /* See comment in dcp_to_content_video */ - return DCPTime::from_frames(f, film->audio_frame_rate()) - DCPTime(_content[0]->trim_start(), frc) + position(); + return DCPTime::from_frames(f, film->audio_frame_rate()) - DCPTime(_content[0]->trim_start(), _frc) + position(); } @@ -110,7 +119,7 @@ ContentTime Piece::dcp_to_content_time (shared_ptr<const Film> film, DCPTime t) const { DCPTime s = t - position(); - s = min (_content[0]->length_after_trim(_film), s); + s = min (_content[0]->length_after_trim(film), s); return max (ContentTime(), ContentTime(s, _frc) + _content[0]->trim_start()); } @@ -157,12 +166,12 @@ Piece::position (shared_ptr<const Film> film) bool Piece::has_text () const { - return !_decoder[0].text.empty(); + return !_decoder[0]->text.empty(); } void -Piece::pass () const +Piece::pass () { _done = _decoder[0]->pass(); } @@ -181,3 +190,86 @@ Piece::video_use () const { return _content[0]->video && _content[0]->video->use(); } + + +Crop +Piece::video_crop () const +{ + return _content[0]->video->crop(); +} + + +optional<double> +Piece::video_fade (boost::shared_ptr<const Film> film, Frame frame) const +{ + return _content[0]->video->fade(film, frame); +} + + +optional<ColourConversion> +Piece::video_colour_conversion () const +{ + return _content[0]->video->colour_conversion(); +} + + +VideoRange +Piece::video_range () const +{ + return _content[0]->video->range(); +} + + +dcp::Size +Piece::video_scaled_size (dcp::Size container_size) const +{ + return _content[0]->video->scaled_size(container_size); +} + + +int +Piece::audio_resampled_frame_rate (shared_ptr<const Film> film) const +{ + return _content[0]->audio->resampled_frame_rate(film); +} + + +double +Piece::audio_gain () const +{ + return _content[0]->audio->gain(); +} + + +void +Piece::seek (shared_ptr<const Film> film, DCPTime time, bool accurate) +{ + if (time < position()) { + /* Before; seek to the start of the content. Even if this request is for an inaccurate seek + we must seek this (following) content accurately, otherwise when we come to the end of the current + content we may not start right at the beginning of the next, causing a gap (if the next content has + been trimmed to a point between keyframes, or something). + */ + _decoder[0]->seek (dcp_to_content_time(film, position()), true); + _done = false; + } else if (position() <= time && time < end(film)) { + /* During; seek to position */ + _decoder[0]->seek (dcp_to_content_time(film, time), accurate); + _done = false; + } else { + /* After; this piece is done */ + _done = true; + } +} + + +optional<DCPTime> +Piece::content_time_to_dcp (shared_ptr<Content> content, ContentTime t) const +{ + if (content != _content[0]) { + return optional<DCPTime>(); + } + + return content_time_to_dcp (t); +} + diff --git a/src/lib/piece.h b/src/lib/piece.h index 845b7fbdc..ad9c939a4 100644 --- a/src/lib/piece.h +++ b/src/lib/piece.h @@ -21,14 +21,19 @@ #ifndef DCPOMATIC_PIECE_H #define DCPOMATIC_PIECE_H + #include "audio_stream.h" -#include "dcpomatic_font.h" +#include "colour_conversion.h" +#include "font.h" #include "dcpomatic_time.h" #include "frame_rate_change.h" #include "types.h" + class Content; class Decoder; +struct check_reuse_old_data_test; + class Piece { @@ -42,6 +47,7 @@ public: bool reference_audio () const; void pass (); + void seek (boost::shared_ptr<const Film> film, dcpomatic::DCPTime time, bool accurate); dcpomatic::DCPTime position () const; dcpomatic::DCPTime end (boost::shared_ptr<const Film> film) const; @@ -50,15 +56,26 @@ public: } bool video_use () const; + Crop video_crop () const; + boost::optional<double> video_fade (boost::shared_ptr<const Film> film, Frame) const; + boost::optional<ColourConversion> video_colour_conversion () const; + VideoRange video_range () const; + dcp::Size video_scaled_size (dcp::Size container_size) const; + + int audio_resampled_frame_rate (boost::shared_ptr<const Film> film) const; + double audio_gain () const; dcpomatic::DCPTime content_video_to_dcp (Frame f) const; dcpomatic::DCPTime resampled_audio_to_dcp (boost::shared_ptr<const Film> film, Frame f) const; dcpomatic::ContentTime dcp_to_content_time (boost::shared_ptr<const Film> film, dcpomatic::DCPTime t) const; dcpomatic::DCPTime content_time_to_dcp (dcpomatic::ContentTime t) const; + boost::optional<dcpomatic::DCPTime> content_time_to_dcp (boost::shared_ptr<Content> content, dcpomatic::ContentTime t) const; void add_fonts (std::list<boost::shared_ptr<dcpomatic::Font> >& fonts) const; private: + friend struct ::check_reuse_old_data_test; + std::vector<boost::shared_ptr<Content> > _content; std::vector<boost::shared_ptr<Decoder> > _decoder; FrameRateChange _frc; diff --git a/src/lib/player.cc b/src/lib/player.cc index 62dc48eeb..7e5ea1ba0 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -379,7 +379,7 @@ Player::black_player_video_frame (Eyes eyes) const PART_WHOLE, PresetColourConversion::all().front().conversion, VIDEO_RANGE_FULL, - boost::weak_ptr<Content>(), + boost::weak_ptr<Piece>(), boost::optional<Frame>(), false ) @@ -813,15 +813,15 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video) _last_video[wp].reset ( new PlayerVideo ( video.image, - piece->content->video->crop (), - piece->content->video->fade (_film, video.frame), - scale_for_display(piece->content->video->scaled_size(_film->frame_size()), _video_container_size, _film->frame_size()), + piece->video_crop(), + piece->video_fade(_film, video.frame), + scale_for_display(piece->video_scaled_size(_film->frame_size()), _video_container_size, _film->frame_size()), _video_container_size, video.eyes, video.part, - piece->content->video->colour_conversion(), - piece->content->video->range(), - piece->content, + piece->video_colour_conversion(), + piece->video_range(), + piece, video.frame, false ) @@ -846,15 +846,11 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a return; } - shared_ptr<AudioContent> content = piece->content->audio; - DCPOMATIC_ASSERT (content); - - int const rfr = content->resampled_frame_rate (_film); + int const rfr = piece->audio_resampled_frame_rate (_film); /* Compute time in the DCP */ - DCPTime time = resampled_audio_to_dcp (piece, content_audio.frame); + DCPTime time = piece->resampled_audio_to_dcp (_film, content_audio.frame); LOG_DEBUG_PLAYER("Received audio frame %1 at %2", content_audio.frame, to_string(time)); - /* And the end of this block in the DCP */ DCPTime end = time + DCPTime::from_frames(content_audio.audio->frames(), rfr); @@ -882,9 +878,9 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a /* Gain */ - if (content->gain() != 0) { + if (piece->audio_gain() != 0) { shared_ptr<AudioBuffers> gain (new AudioBuffers (content_audio.audio)); - gain->apply_gain (content->gain ()); + gain->apply_gain (piece->audio_gain()); content_audio.audio = gain; } @@ -1008,7 +1004,7 @@ Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, Conte return; } - DCPTime const dcp_to = content_time_to_dcp (piece, to); + DCPTime const dcp_to = piece->content_time_to_dcp (to); if (dcp_to > piece->end(_film)) { return; @@ -1049,22 +1045,7 @@ Player::seek (DCPTime time, bool accurate) } BOOST_FOREACH (shared_ptr<Piece> i, _pieces) { - if (time < i->position()) { - /* Before; seek to the start of the content. Even if this request is for an inaccurate seek - we must seek this (following) content accurately, otherwise when we come to the end of the current - content we may not start right at the beginning of the next, causing a gap (if the next content has - been trimmed to a point between keyframes, or something). - */ - i->decoder->seek (dcp_to_content_time (i, i->position()), true); - i->done = false; - } else if (i->position() <= time && time < i->end(_film)) { - /* During; seek to position */ - i->decoder->seek (dcp_to_content_time (i, time), accurate); - i->done = false; - } else { - /* After; this piece is done */ - i->done = true; - } + i->seek (_film, time, accurate); } if (accurate) { @@ -1204,8 +1185,9 @@ Player::content_time_to_dcp (shared_ptr<Content> content, ContentTime t) boost::mutex::scoped_lock lm (_mutex); BOOST_FOREACH (shared_ptr<Piece> i, _pieces) { - if (i->content == content) { - return content_time_to_dcp (i, t); + optional<DCPTime> d = i->content_time_to_dcp (content, t); + if (d) { + return d; } } diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index 4f8acd5e2..2fc60570f 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -18,6 +18,7 @@ */ +#include "piece.h" #include "player_video.h" #include "content.h" #include "video_content.h" @@ -54,7 +55,7 @@ PlayerVideo::PlayerVideo ( Part part, optional<ColourConversion> colour_conversion, VideoRange video_range, - weak_ptr<Content> content, + weak_ptr<Piece> piece, optional<Frame> video_frame, bool error ) @@ -67,7 +68,7 @@ PlayerVideo::PlayerVideo ( , _part (part) , _colour_conversion (colour_conversion) , _video_range (video_range) - , _content (content) + , _piece (piece) , _video_frame (video_frame) , _error (error) { @@ -320,7 +321,7 @@ PlayerVideo::shallow_copy () const _part, _colour_conversion, _video_range, - _content, + _piece, _video_frame, _error ) @@ -333,17 +334,17 @@ PlayerVideo::shallow_copy () const bool PlayerVideo::reset_metadata (shared_ptr<const Film> film, dcp::Size player_video_container_size) { - shared_ptr<Content> content = _content.lock(); - if (!content || !_video_frame) { + shared_ptr<Piece> piece = _piece.lock(); + if (!piece || !_video_frame) { return false; } - _crop = content->video->crop(); - _fade = content->video->fade(film, _video_frame.get()); - _inter_size = scale_for_display(content->video->scaled_size(film->frame_size()), player_video_container_size, film->frame_size()); - _out_size = player_video_container_size; - _colour_conversion = content->video->colour_conversion(); - _video_range = content->video->range(); + _crop = piece->video_crop(); + _fade = piece->video_fade(film, _video_frame.get()); + _inter_size = scale_for_display(piece->video_scaled_size(film->frame_size()), player_video_container_size, film->frame_size()); + _out_size = video_container_size; + _colour_conversion = piece->video_colour_conversion(); + _video_range = piece->video_range(); return true; } diff --git a/src/lib/player_video.h b/src/lib/player_video.h index 0952eafb9..65f5111c3 100644 --- a/src/lib/player_video.h +++ b/src/lib/player_video.h @@ -22,6 +22,7 @@ #define DCPOMATIC_PLAYER_VIDEO_H #include "types.h" +#include "piece.h" #include "position.h" #include "dcpomatic_time.h" #include "colour_conversion.h" @@ -56,7 +57,7 @@ public: Part, boost::optional<ColourConversion>, VideoRange video_range, - boost::weak_ptr<Content>, + boost::weak_ptr<Piece>, boost::optional<Frame>, bool error ); @@ -105,8 +106,8 @@ public: size_t memory_used () const; - boost::weak_ptr<Content> content () const { - return _content; + boost::weak_ptr<Piece> piece () const { + return _piece; } bool error () const { @@ -126,8 +127,9 @@ private: boost::optional<ColourConversion> _colour_conversion; VideoRange _video_range; boost::optional<PositionImage> _text; - /** Content that we came from. This is so that reset_metadata() can work. */ - boost::weak_ptr<Content> _content; + /** Piece that we came from. This is so that reset_metadata() can work. */ + */ + boost::weak_ptr<Piece> _piece; /** Video frame that we came from. Again, this is for reset_metadata() */ boost::optional<Frame> _video_frame; |
