Add and use new FrameRateChange constructors.
authorCarl Hetherington <cth@carlh.net>
Wed, 21 Nov 2018 12:15:26 +0000 (12:15 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 21 Nov 2018 12:15:26 +0000 (12:15 +0000)
19 files changed:
src/lib/atmos_mxf_content.cc
src/lib/atmos_mxf_content.h
src/lib/audio_content.cc
src/lib/dcp_content.cc
src/lib/dcp_subtitle_content.cc
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
src/lib/frame_rate_change.cc
src/lib/frame_rate_change.h
src/lib/image_content.cc
src/lib/image_content.h
src/lib/player.cc
src/lib/string_text_file_content.cc
src/lib/string_text_file_content.h
src/lib/video_mxf_content.cc
src/lib/video_mxf_content.h
src/tools/dcpomatic.cc
src/tools/dcpomatic_cli.cc
src/tools/dcpomatic_create.cc

index 8300c2cd6e4e9026fefe9efa731e56682aeb0d87..4835442d5e5f01b3eb973f84ab7e888449d8e9f6 100644 (file)
@@ -93,6 +93,6 @@ AtmosMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const
 DCPTime
 AtmosMXFContent::full_length (shared_ptr<const Film> film) const
 {
-       FrameRateChange const frc (active_video_frame_rate(film), film->video_frame_rate());
+       FrameRateChange const frc (film, shared_from_this());
        return DCPTime::from_frames (llrint (_length * frc.factor()), film->video_frame_rate());
 }
index 156ebc7888c708d94517207f1c02cc02c4ae87dd..854824c67d82d76ca63d6d6da802fadb6291ddef 100644 (file)
@@ -30,6 +30,10 @@ public:
                return boost::dynamic_pointer_cast<AtmosMXFContent> (Content::shared_from_this ());
        }
 
+       boost::shared_ptr<const AtmosMXFContent> shared_from_this () const {
+               return boost::dynamic_pointer_cast<const AtmosMXFContent> (Content::shared_from_this ());
+       }
+
        void examine (boost::shared_ptr<const Film> film, boost::shared_ptr<Job> job);
        std::string summary () const;
        void as_xml (xmlpp::Node* node, bool with_path) const;
index f3372011933c724985e2b172d8e37124ad908d91..b513fb443de0ec3e6631914bf3a1f1299a8bfe87 100644 (file)
@@ -199,7 +199,7 @@ AudioContent::resampled_frame_rate (shared_ptr<const Film> film) const
        /* Resample to a DCI-approved sample rate */
        double t = has_rate_above_48k() ? 96000 : 48000;
 
-       FrameRateChange frc (_parent->active_video_frame_rate(film), film->video_frame_rate());
+       FrameRateChange frc (film, _parent);
 
        /* Compensate if the DCP is being run at a different frame rate
           to the source; that is, if the video is run such that it will
index 62284e4333e06a1ceb62bfaebc99fd83a41a7ab4..3110f93ad5eb6b61abf18ceb1e752da5f7647b7b 100644 (file)
@@ -342,7 +342,7 @@ DCPContent::full_length (shared_ptr<const Film> film) const
        if (!video) {
                return DCPTime();
        }
-       FrameRateChange const frc (active_video_frame_rate(film), film->video_frame_rate());
+       FrameRateChange const frc (film, shared_from_this());
        return DCPTime::from_frames (llrint(video->length() * frc.factor()), film->video_frame_rate());
 }
 
index 21a50c1990db485f4c20c3b71ba4349f20cd6e0d..d25e06188b95de79ab189e9cbc03b1a8af5adad2 100644 (file)
@@ -84,7 +84,7 @@ DCPSubtitleContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
 DCPTime
 DCPSubtitleContent::full_length (shared_ptr<const Film> film) const
 {
-       FrameRateChange const frc (active_video_frame_rate(film), film->video_frame_rate());
+       FrameRateChange const frc (film, shared_from_this());
        return DCPTime (_length, frc);
 }
 
index 2b494dc9233259afdf2f73e30c1c015777b311ed..fcadc91165ab12179b9e1987467fd912115d97fa 100644 (file)
@@ -402,7 +402,7 @@ operator!= (FFmpegStream const & a, FFmpegStream const & b)
 DCPTime
 FFmpegContent::full_length (shared_ptr<const Film> film) const
 {
-       FrameRateChange const frc (active_video_frame_rate(film), film->video_frame_rate());
+       FrameRateChange const frc (film, shared_from_this());
        if (video) {
                return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film->video_frame_rate());
        }
index 8bd5ef4fa9b05ab1ddd80dfc433fa94d793ddef7..b7685bf0937c56f92b1cfea4e65aea1c2f114785 100644 (file)
@@ -54,6 +54,10 @@ public:
                return boost::dynamic_pointer_cast<FFmpegContent> (Content::shared_from_this ());
        }
 
+       boost::shared_ptr<const FFmpegContent> shared_from_this () const {
+               return boost::dynamic_pointer_cast<const FFmpegContent> (Content::shared_from_this ());
+       }
+
        void examine (boost::shared_ptr<const Film> film, boost::shared_ptr<Job>);
        void take_settings_from (boost::shared_ptr<const Content> c);
        std::string summary () const;
index 80a167029009349913b21e15c35d6aa0c760b4f2..456b4151e1a11accef6e1d6b481955c65e71a4c2 100644 (file)
 
 #include "frame_rate_change.h"
 #include "types.h"
+#include "content.h"
+#include "film.h"
 #include "compose.hpp"
 #include <cmath>
 
 #include "i18n.h"
 
 using std::string;
+using boost::shared_ptr;
 
 static bool
 about_equal (double a, double b)
@@ -33,14 +36,20 @@ about_equal (double a, double b)
        return (fabs (a - b) < VIDEO_FRAME_RATE_EPSILON);
 }
 
-
 FrameRateChange::FrameRateChange (double source_, int dcp_)
-       : source (source_)
-       , dcp (dcp_)
-       , skip (false)
+       : skip (false)
        , repeat (1)
        , change_speed (false)
 {
+       construct (source_, dcp_);
+}
+
+void
+FrameRateChange::construct (double source_, int dcp_)
+{
+       source = source_;
+       dcp = dcp_;
+
        if (fabs (source / 2.0 - dcp) < fabs (source - dcp)) {
                /* The difference between source and DCP frame rate will be lower
                   (i.e. better) if we skip.
@@ -58,6 +67,16 @@ FrameRateChange::FrameRateChange (double source_, int dcp_)
        change_speed = !about_equal (speed_up, 1.0);
 }
 
+FrameRateChange::FrameRateChange (shared_ptr<const Film> film, shared_ptr<const Content> content)
+{
+       construct (content->active_video_frame_rate(film), film->video_frame_rate());
+}
+
+FrameRateChange::FrameRateChange (shared_ptr<const Film> film, Content const * content)
+{
+       construct (content->active_video_frame_rate(film), film->video_frame_rate());
+}
+
 string
 FrameRateChange::description () const
 {
index ae3615328d7ce3e5dfccddc596611ad8c40cdeb1..05660ce826f07edfc1cada2eb5ca56a06ad731b2 100644 (file)
 #ifndef DCPOMATIC_FRAME_RATE_CHANGE_H
 #define DCPOMATIC_FRAME_RATE_CHANGE_H
 
+#include <boost/shared_ptr.hpp>
 #include <string>
 
-struct FrameRateChange
+class Film;
+class Content;
+
+class FrameRateChange
 {
+public:
        FrameRateChange (double, int);
+       FrameRateChange (boost::shared_ptr<const Film> film, boost::shared_ptr<const Content> content);
+       FrameRateChange (boost::shared_ptr<const Film> film, Content const * content);
 
        /** @return factor by which to multiply a source frame rate
            to get the effective rate after any skip or repeat has happened.
@@ -62,6 +69,9 @@ struct FrameRateChange
        double speed_up;
 
        std::string description () const;
+
+private:
+       void construct (double source_, int dcp_);
 };
 
 #endif
index 55ffac4f251f786ba9393307d1df24e561e0a785..c84ba7d29019c3f0575170678254c4649f27c97d 100644 (file)
@@ -135,7 +135,7 @@ ImageContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
 DCPTime
 ImageContent::full_length (shared_ptr<const Film> film) const
 {
-       FrameRateChange const frc (active_video_frame_rate(film), film->video_frame_rate());
+       FrameRateChange const frc (film, shared_from_this());
        return DCPTime::from_frames (llrint(video->length_after_3d_combine() * frc.factor()), film->video_frame_rate());
 }
 
index bc0f331515f861f71134706c661b246f7efd8b2e..6a450ef8f33721b5903179118c809ce41b88b9fb 100644 (file)
@@ -33,6 +33,10 @@ public:
                return boost::dynamic_pointer_cast<ImageContent> (Content::shared_from_this ());
        };
 
+       boost::shared_ptr<const ImageContent> shared_from_this () const {
+               return boost::dynamic_pointer_cast<const ImageContent> (Content::shared_from_this ());
+       };
+
        void examine (boost::shared_ptr<const Film> film, boost::shared_ptr<Job>);
        std::string summary () const;
        std::string technical_summary () const;
index 80b9744d8505a884c60d5cc8712ecce90b05cabb..5a71c133001016b893e6457399d1a8ed1318855e 100644 (file)
@@ -156,7 +156,7 @@ Player::setup_pieces_unlocked ()
                }
 
                shared_ptr<Decoder> decoder = decoder_factory (_film, i, _fast);
-               FrameRateChange frc (i->active_video_frame_rate(_film), _film->video_frame_rate());
+               FrameRateChange frc (_film, i);
 
                if (!decoder) {
                        /* Not something that we can decode; e.g. Atmos content */
@@ -735,7 +735,7 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
                return;
        }
 
-       FrameRateChange frc(piece->content->active_video_frame_rate(_film), _film->video_frame_rate());
+       FrameRateChange frc (_film, piece->content);
        if (frc.skip && (video.frame % 2) == 1) {
                return;
        }
index 35f76be7c4d1894346a4426363a1aba4f416060c..8b740546e82004c47299b514650e5384f11fe197 100644 (file)
@@ -91,6 +91,6 @@ StringTextFileContent::as_xml (xmlpp::Node* node, bool with_paths) const
 DCPTime
 StringTextFileContent::full_length (shared_ptr<const Film> film) const
 {
-       FrameRateChange const frc (active_video_frame_rate(film), film->video_frame_rate());
+       FrameRateChange const frc (film, shared_from_this());
        return DCPTime (_length, frc);
 }
index 9a71d5828696683aa6b97b5b460c0eeda1ed377e..4932f2a72dbc5feaa52a9ab54d21a18877cb591a 100644 (file)
@@ -35,6 +35,10 @@ public:
                return boost::dynamic_pointer_cast<StringTextFileContent> (Content::shared_from_this ());
        }
 
+       boost::shared_ptr<const StringTextFileContent> shared_from_this () const {
+               return boost::dynamic_pointer_cast<const StringTextFileContent> (Content::shared_from_this ());
+       }
+
        void examine (boost::shared_ptr<const Film> film, boost::shared_ptr<Job>);
        std::string summary () const;
        std::string technical_summary () const;
index 4f69cb2e2301ed1fb76d2395b25b058934638dbd..def58c5ebb3a5a7bc0e69dcccc2df31be1ed82b0 100644 (file)
@@ -119,7 +119,7 @@ VideoMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const
 DCPTime
 VideoMXFContent::full_length (shared_ptr<const Film> film) const
 {
-       FrameRateChange const frc (active_video_frame_rate(film), film->video_frame_rate());
+       FrameRateChange const frc (film, shared_from_this());
        return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film->video_frame_rate());
 }
 
index c536cb2aa99da5fe7e8ee3177c777d2a945be6a5..6236568b1cad89837627c98ad5f68531e9173d2f 100644 (file)
@@ -30,6 +30,10 @@ public:
                return boost::dynamic_pointer_cast<VideoMXFContent> (Content::shared_from_this ());
        }
 
+       boost::shared_ptr<const VideoMXFContent> shared_from_this () const {
+               return boost::dynamic_pointer_cast<const VideoMXFContent> (Content::shared_from_this ());
+       }
+
        void examine (boost::shared_ptr<const Film> film, boost::shared_ptr<Job> job);
        std::string summary () const;
        std::string technical_summary () const;
index 3d74859dc9e139ec9d97e01386386f1f3a562884..15c4363ee3587d0ef4ae96b9fe00ebe6ef346bd1 100644 (file)
@@ -595,7 +595,7 @@ private:
        {
                ContentList const sel = _film_editor->content_panel()->selected();
                DCPOMATIC_ASSERT (sel.size() == 1);
-               _clipboard = sel.front()->clone();
+               _clipboard = sel.front()->clone(_film);
        }
 
        void edit_paste ()
@@ -873,7 +873,7 @@ private:
        {
                ContentList vc = _film_editor->content_panel()->selected_video ();
                for (ContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
-                       (*i)->video->scale_and_crop_to_fit_width ();
+                       (*i)->video->scale_and_crop_to_fit_width (_film);
                }
        }
 
@@ -881,7 +881,7 @@ private:
        {
                ContentList vc = _film_editor->content_panel()->selected_video ();
                for (ContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
-                       (*i)->video->scale_and_crop_to_fit_height ();
+                       (*i)->video->scale_and_crop_to_fit_height (_film);
                }
        }
 
@@ -1445,12 +1445,12 @@ private:
                if (!_film_to_create.empty ()) {
                        _frame->new_film (_film_to_create, optional<string> ());
                        if (!_content_to_add.empty ()) {
-                               BOOST_FOREACH (shared_ptr<Content> i, content_factory (_frame->film(), _content_to_add)) {
+                               BOOST_FOREACH (shared_ptr<Content> i, content_factory(_content_to_add)) {
                                        _frame->film()->examine_and_add_content (i);
                                }
                        }
                        if (!_dcp_to_add.empty ()) {
-                               _frame->film()->examine_and_add_content (shared_ptr<DCPContent> (new DCPContent (_frame->film(), _dcp_to_add)));
+                               _frame->film()->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent(_dcp_to_add)));
                        }
                }
 
index 7fc5ed55dd9603d702eb4496adf6b37649b73629..779e0ad266d57f7421806c5038c37c02e69664c6 100644 (file)
@@ -84,13 +84,13 @@ print_dump (shared_ptr<Film> film)
                cout << "\n"
                     << c->path(0) << "\n"
                     << "\tat " << c->position().seconds ()
-                    << " length " << c->full_length().seconds ()
+                    << " length " << c->full_length(film).seconds ()
                     << " start trim " << c->trim_start().seconds ()
                     << " end trim " << c->trim_end().seconds () << "\n";
 
                if (c->video) {
                        cout << "\t" << c->video->size().width << "x" << c->video->size().height << "\n"
-                            << "\t" << c->active_video_frame_rate() << "fps\n"
+                            << "\t" << c->active_video_frame_rate(film) << "fps\n"
                             << "\tcrop left " << c->video->left_crop()
                             << " right " << c->video->right_crop()
                             << " top " << c->video->top_crop()
index da2ce0b72a29b45b117241fa745ef51f390ec3d6..af3a68b6191630b6f4d836e094a1740023aa4c74 100644 (file)
@@ -251,10 +251,10 @@ main (int argc, char* argv[])
                        list<shared_ptr<Content> > content;
 
                        if (boost::filesystem::exists (can / "ASSETMAP") || (boost::filesystem::exists (can / "ASSETMAP.xml"))) {
-                               content.push_back (shared_ptr<DCPContent> (new DCPContent (film, can)));
+                               content.push_back (shared_ptr<DCPContent>(new DCPContent(can)));
                        } else {
                                /* I guess it's not a DCP */
-                               content = content_factory (film, can);
+                               content = content_factory (can);
                        }
 
                        BOOST_FOREACH (shared_ptr<Content> j, content) {