Clean up a bit by using Content::film() more.
authorCarl Hetherington <cth@carlh.net>
Fri, 6 Nov 2015 01:29:06 +0000 (01:29 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 6 Nov 2015 01:29:06 +0000 (01:29 +0000)
src/lib/audio_content.cc
src/lib/content.cc
src/lib/content.h
src/lib/dcp_content.cc
src/lib/dcp_subtitle_content.cc
src/lib/ffmpeg_content.cc
src/lib/single_stream_audio_content.cc
src/lib/sndfile_content.cc
src/lib/subrip_content.cc
src/lib/video_content.cc

index c67a66ed8a00f669e768a32db5be27626524eb19..838fdcae2b570c3bdd594f95ca131bc40878f21f 100644 (file)
@@ -191,13 +191,10 @@ AudioContent::audio_mapping () const
 int
 AudioContent::resampled_audio_frame_rate () const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-
        /* Resample to a DCI-approved sample rate */
        double t = has_rate_above_48k() ? 96000 : 48000;
 
-       FrameRateChange frc = film->active_frame_rate_change (position ());
+       FrameRateChange frc = film()->active_frame_rate_change (position ());
 
        /* 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 aa596f75a3f931ed0fc83b52914b737e6db600d4..af85e0ff08d17fcbf7fd4111ce27988d9fe405dd 100644 (file)
@@ -223,9 +223,7 @@ Content::technical_summary () const
 DCPTime
 Content::length_after_trim () const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       return max (DCPTime (), full_length() - DCPTime (trim_start() + trim_end(), film->active_frame_rate_change (position ())));
+       return max (DCPTime (), full_length() - DCPTime (trim_start() + trim_end(), film()->active_frame_rate_change (position ())));
 }
 
 /** @return string which changes when something about this content changes which affects
@@ -289,3 +287,11 @@ Content::properties () const
        add_properties (p);
        return p;
 }
+
+shared_ptr<const Film>
+Content::film () const
+{
+       shared_ptr<const Film> film = _film.lock ();
+       DCPOMATIC_ASSERT (film);
+       return film;
+}
index 14fa3c36a933b3f0389bb84917a1b90363567aa1..b91b5778c8be7f855fbb25f3db9d24ed13550968 100644 (file)
@@ -156,9 +156,7 @@ public:
                _change_signals_frequent = f;
        }
 
-       boost::shared_ptr<const Film> film () const {
-               return _film.lock ();
-       }
+       boost::shared_ptr<const Film> film () const;
 
        boost::signals2::signal<void (boost::weak_ptr<Content>, int, bool)> Changed;
 
index 85fbee0128d211657855867a43a92944f0502d21..f65aaec7e08511ccc6e3ffa05a8d9c279a8b2de6 100644 (file)
@@ -161,10 +161,8 @@ DCPContent::as_xml (xmlpp::Node* node) const
 DCPTime
 DCPContent::full_length () const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ());
-       return DCPTime::from_frames (llrint (video_length () * frc.factor ()), film->video_frame_rate ());
+       FrameRateChange const frc (video_frame_rate (), film()->video_frame_rate ());
+       return DCPTime::from_frames (llrint (video_length () * frc.factor ()), film()->video_frame_rate ());
 }
 
 string
@@ -266,11 +264,9 @@ DCPContent::reels () const
                return p;
        }
 
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
        DCPTime from = position ();
        BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder->reels()) {
-               DCPTime const to = from + DCPTime::from_frames (i->main_picture()->duration(), film->video_frame_rate());
+               DCPTime const to = from + DCPTime::from_frames (i->main_picture()->duration(), film()->video_frame_rate());
                p.push_back (DCPTimePeriod (from, to));
                from = to;
        }
@@ -292,10 +288,7 @@ template <class T>
 bool
 DCPContent::can_reference (string overlapping, list<string>& why_not) const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-
-       list<DCPTimePeriod> const fr = film->reels ();
+       list<DCPTimePeriod> const fr = film()->reels ();
        /* fr must contain reels().  It can also contain other reels, but it must at
           least contain reels().
        */
@@ -306,7 +299,7 @@ DCPContent::can_reference (string overlapping, list<string>& why_not) const
                }
        }
 
-       list<shared_ptr<T> > a = overlaps<T> (film->content(), position(), end());
+       list<shared_ptr<T> > a = overlaps<T> (film()->content(), position(), end());
        if (a.size() != 1 || a.front().get() != this) {
                why_not.push_back (overlapping);
                return false;
index 19f38c5f64732fd230c0dfa713ea968aa3e846aa..39f24b21514c01d1bdb7247ac44366aff4fc2e16 100644 (file)
@@ -82,9 +82,7 @@ DCPSubtitleContent::examine (shared_ptr<Job> job)
 DCPTime
 DCPSubtitleContent::full_length () const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       FrameRateChange const frc (subtitle_video_frame_rate(), film->video_frame_rate());
+       FrameRateChange const frc (subtitle_video_frame_rate(), film()->video_frame_rate());
        return DCPTime (_length, frc);
 }
 
@@ -133,7 +131,5 @@ DCPSubtitleContent::subtitle_video_frame_rate () const
        /* No frame rate specified, so assume this content has been
           prepared for any concurrent video content.
        */
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       return film->active_frame_rate_change(position()).source;
+       return film()->active_frame_rate_change(position()).source;
 }
index 6df97a48535f1e8b56f65a94cc8a55f51d9015c6..a317ec35fee91ad4d45c7668b9bca6e06e7dcda0 100644 (file)
@@ -187,9 +187,6 @@ FFmpegContent::examine (shared_ptr<Job> job)
        shared_ptr<FFmpegExaminer> examiner (new FFmpegExaminer (shared_from_this (), job));
        take_from_video_examiner (examiner);
 
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-
        {
                boost::mutex::scoped_lock lm (_mutex);
 
@@ -202,7 +199,7 @@ FFmpegContent::examine (shared_ptr<Job> job)
 
                if (!_audio_streams.empty ()) {
                        AudioMapping m = _audio_streams.front()->mapping ();
-                       film->make_audio_mapping_default (m);
+                       film()->make_audio_mapping_default (m);
                        _audio_streams.front()->set_mapping (m);
                }
 
@@ -280,10 +277,8 @@ operator!= (FFmpegStream const & a, FFmpegStream const & b)
 DCPTime
 FFmpegContent::full_length () const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ());
-       return DCPTime::from_frames (llrint (video_length_after_3d_combine() * frc.factor()), film->video_frame_rate());
+       FrameRateChange const frc (video_frame_rate (), film()->video_frame_rate ());
+       return DCPTime::from_frames (llrint (video_length_after_3d_combine() * frc.factor()), film()->video_frame_rate());
 }
 
 void
index 05b055865fbef18a414f29b744f6a7bbcce441e6..4c59420cbfe16b3c350e13235ff01926dbde1251 100644 (file)
@@ -66,14 +66,11 @@ SingleStreamAudioContent::as_xml (xmlpp::Node* node) const
 void
 SingleStreamAudioContent::take_from_audio_examiner (shared_ptr<AudioExaminer> examiner)
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-
        {
                boost::mutex::scoped_lock lm (_mutex);
                _audio_stream.reset (new AudioStream (examiner->audio_frame_rate(), examiner->audio_channels ()));
                AudioMapping m = _audio_stream->mapping ();
-               film->make_audio_mapping_default (m);
+               film()->make_audio_mapping_default (m);
                _audio_stream->set_mapping (m);
        }
 
index dc26a1a7e17655f6f91521862a86cd8f6ac67bc7..c4f418775f7d4126c1a824a2e13b35d08d2f25df 100644 (file)
@@ -106,8 +106,6 @@ SndfileContent::take_from_audio_examiner (shared_ptr<AudioExaminer> examiner)
 DCPTime
 SndfileContent::full_length () const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       FrameRateChange const frc = film->active_frame_rate_change (position ());
+       FrameRateChange const frc = film()->active_frame_rate_change (position ());
        return DCPTime::from_frames (audio_length() / frc.speed_up, audio_stream()->frame_rate ());
 }
index ba081624ac6ba166d0152ba2d5f8e3e0921823ff..1a7efc117a345e6c6a836713eac731de9c4290f0 100644 (file)
@@ -89,9 +89,7 @@ SubRipContent::as_xml (xmlpp::Node* node) const
 DCPTime
 SubRipContent::full_length () const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       FrameRateChange const frc (subtitle_video_frame_rate(), film->video_frame_rate ());
+       FrameRateChange const frc (subtitle_video_frame_rate(), film()->video_frame_rate ());
        return DCPTime (_length, frc);
 }
 
@@ -119,7 +117,5 @@ SubRipContent::subtitle_video_frame_rate () const
        /* No frame rate specified, so assume this content has been
           prepared for any concurrent video content.
        */
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       return film->active_frame_rate_change(position()).source;
+       return film()->active_frame_rate_change(position()).source;
 }
index f11b40bb44b7b61d800242832ddfa08b263ef3cf..498d5b9db7f3215dd870bb40db3fc2c4ff29e646 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "i18n.h"
 
-#define LOG_GENERAL(...) film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
+#define LOG_GENERAL(...) film()->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
 
 int const VideoContentProperty::VIDEO_SIZE       = 0;
 int const VideoContentProperty::VIDEO_FRAME_RATE  = 1;
@@ -236,8 +236,6 @@ VideoContent::take_from_video_examiner (shared_ptr<VideoExaminer> d)
                        );
        }
 
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
        LOG_GENERAL ("Video length obtained from header as %1 frames", _video_length);
 
        set_default_colour_conversion ();
@@ -447,12 +445,9 @@ VideoContent::video_size_after_crop () const
 void
 VideoContent::scale_and_crop_to_fit_width ()
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
+       set_scale (VideoContentScale (film()->container ()));
 
-       set_scale (VideoContentScale (film->container ()));
-
-       int const crop = max (0, int (video_size().height - double (film->frame_size().height) * video_size().width / film->frame_size().width));
+       int const crop = max (0, int (video_size().height - double (film()->frame_size().height) * video_size().width / film()->frame_size().width));
        set_top_crop (crop / 2);
        set_bottom_crop (crop / 2);
 }
@@ -460,12 +455,9 @@ VideoContent::scale_and_crop_to_fit_width ()
 void
 VideoContent::scale_and_crop_to_fit_height ()
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-
-       set_scale (VideoContentScale (film->container ()));
+       set_scale (VideoContentScale (film()->container ()));
 
-       int const crop = max (0, int (video_size().width - double (film->frame_size().width) * video_size().height / film->frame_size().height));
+       int const crop = max (0, int (video_size().width - double (film()->frame_size().width) * video_size().height / film()->frame_size().height));
        set_left_crop (crop / 2);
        set_right_crop (crop / 2);
 }
@@ -536,10 +528,7 @@ VideoContent::processing_description () const
                d << " (" << fixed << setprecision(2) << cropped.ratio () << ":1)\n";
        }
 
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-
-       dcp::Size const container_size = film->frame_size ();
+       dcp::Size const container_size = film()->frame_size ();
        dcp::Size const scaled = scale().size (dynamic_pointer_cast<const VideoContent> (shared_from_this ()), container_size, container_size);
 
        if (scaled != video_size_after_crop ()) {
@@ -554,7 +543,7 @@ VideoContent::processing_description () const
        if (scaled != container_size) {
                d << String::compose (
                        _("Padded with black to fit container %1 (%2x%3)"),
-                       film->container()->nickname (),
+                       film()->container()->nickname (),
                        container_size.width, container_size.height
                        );
 
@@ -564,7 +553,7 @@ VideoContent::processing_description () const
        d << _("Content frame rate");
        d << " " << fixed << setprecision(4) << video_frame_rate() << "\n";
 
-       FrameRateChange frc (video_frame_rate(), film->video_frame_rate ());
+       FrameRateChange frc (video_frame_rate(), film()->video_frame_rate ());
        d << frc.description () << "\n";
 
        return d.str ();
@@ -582,19 +571,14 @@ list<DCPTime>
 VideoContent::reel_split_points () const
 {
        list<DCPTime> t;
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
        /* XXX: this is questionable; perhaps the position should be forced to be on a frame boundary */
-       t.push_back (position().round_up (film->video_frame_rate()));
+       t.push_back (position().round_up (film()->video_frame_rate()));
        return t;
 }
 
 double
 VideoContent::video_frame_rate () const
 {
-       boost::shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-
        boost::mutex::scoped_lock lm (_mutex);
-       return _video_frame_rate.get_value_or (film->video_frame_rate ());
+       return _video_frame_rate.get_value_or (film()->video_frame_rate ());
 }