summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-12-06 21:36:37 +0100
committerCarl Hetherington <cth@carlh.net>2020-12-07 01:20:25 +0100
commitdfb68bf9190ec0be31f01b61c17aebc8b6e30ad8 (patch)
tree7df185b2773729f244ab19622f10eb5f746b661f /src/lib
parent7c27dff5817715965e86798108c596f9a1675394 (diff)
Add WeakFilm and WeakConstFilm and use them a bit.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/decoder.cc10
-rw-r--r--src/lib/decoder.h9
-rw-r--r--src/lib/hints.cc11
-rw-r--r--src/lib/hints.h5
-rw-r--r--src/lib/weak_film.h57
5 files changed, 63 insertions, 29 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc
index 0f2bc4358..d51282b53 100644
--- a/src/lib/decoder.cc
+++ b/src/lib/decoder.cc
@@ -32,7 +32,7 @@ using boost::weak_ptr;
using namespace dcpomatic;
Decoder::Decoder (weak_ptr<const Film> film)
- : _film (film)
+ : WeakConstFilm (film)
{
}
@@ -93,11 +93,3 @@ Decoder::only_text () const
}
return text.front ();
}
-
-shared_ptr<const Film>
-Decoder::film () const
-{
- shared_ptr<const Film> f = _film.lock ();
- DCPOMATIC_ASSERT (f);
- return f;
-}
diff --git a/src/lib/decoder.h b/src/lib/decoder.h
index 316109ebb..97de208b2 100644
--- a/src/lib/decoder.h
+++ b/src/lib/decoder.h
@@ -28,6 +28,7 @@
#include "types.h"
#include "film.h"
#include "dcpomatic_time.h"
+#include "weak_film.h"
#include <boost/utility.hpp>
class Decoded;
@@ -40,7 +41,7 @@ class DecoderPart;
/** @class Decoder.
* @brief Parent class for decoders of content.
*/
-class Decoder : public boost::noncopyable
+class Decoder : public boost::noncopyable, public WeakConstFilm
{
public:
Decoder (boost::weak_ptr<const Film> film);
@@ -60,12 +61,6 @@ public:
virtual void seek (dcpomatic::ContentTime time, bool accurate);
virtual dcpomatic::ContentTime position () const;
-
-protected:
- boost::shared_ptr<const Film> film () const;
-
-private:
- boost::weak_ptr<const Film> _film;
};
#endif
diff --git a/src/lib/hints.cc b/src/lib/hints.cc
index 23d5a15fb..5c9d3d8a4 100644
--- a/src/lib/hints.cc
+++ b/src/lib/hints.cc
@@ -56,7 +56,7 @@ using namespace boost::placeholders;
#endif
Hints::Hints (weak_ptr<const Film> film)
- : _film (film)
+ : WeakConstFilm (film)
, _long_ccap (false)
, _overlap_ccap (false)
, _too_many_ccap_lines (false)
@@ -460,15 +460,6 @@ Hints::open_subtitle (PlayerText text, DCPTimePeriod period)
}
-shared_ptr<const Film>
-Hints::film () const
-{
- shared_ptr<const Film> film = _film.lock ();
- DCPOMATIC_ASSERT (film);
- return film;
-}
-
-
void
Hints::check_ffec_and_ffmc_in_smpte_feature ()
{
diff --git a/src/lib/hints.h b/src/lib/hints.h
index e10037763..b8a831301 100644
--- a/src/lib/hints.h
+++ b/src/lib/hints.h
@@ -23,6 +23,7 @@
#include "types.h"
#include "dcp_text_track.h"
#include "dcpomatic_time.h"
+#include "weak_film.h"
#include <boost/weak_ptr.hpp>
#include <boost/signals2.hpp>
#include <boost/atomic.hpp>
@@ -31,7 +32,7 @@
class Film;
-class Hints : public Signaller, public ExceptionStore
+class Hints : public Signaller, public ExceptionStore, public WeakConstFilm
{
public:
explicit Hints (boost::weak_ptr<const Film> film);
@@ -55,7 +56,6 @@ private:
void text (PlayerText text, TextType type, dcpomatic::DCPTimePeriod period);
void closed_caption (PlayerText text, dcpomatic::DCPTimePeriod period);
void open_subtitle (PlayerText text, dcpomatic::DCPTimePeriod period);
- boost::shared_ptr<const Film> film () const;
void check_big_font_files ();
void check_few_audio_channels ();
@@ -70,7 +70,6 @@ private:
void check_loudness ();
void check_ffec_and_ffmc_in_smpte_feature ();
- boost::weak_ptr<const Film> _film;
boost::thread _thread;
bool _long_ccap;
diff --git a/src/lib/weak_film.h b/src/lib/weak_film.h
new file mode 100644
index 000000000..731101474
--- /dev/null
+++ b/src/lib/weak_film.h
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#ifndef DCPOMATIC_WEAK_FILM_H
+#define DCPOMATIC_WEAK_FILM_H
+
+
+#include "dcpomatic_assert.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+
+
+class Film;
+
+
+template <class T>
+class WeakFilmTemplate
+{
+public:
+ WeakFilmTemplate (boost::weak_ptr<T> f)
+ : _film(f)
+ {}
+
+protected:
+ boost::weak_ptr<T> _film;
+
+ boost::shared_ptr<T> film () const {
+ boost::shared_ptr<T> f = _film.lock();
+ DCPOMATIC_ASSERT (f);
+ return f;
+ }
+};
+
+
+typedef WeakFilmTemplate<const Film> WeakConstFilm;
+typedef WeakFilmTemplate<Film> WeakFilm;
+
+
+#endif