Basic (untested) ebur128 (#368).
[dcpomatic.git] / src / lib / dcp_content.cc
index 747216f3c666853a212bc3291d7262c0b744ed11..f65aaec7e08511ccc6e3ffa05a8d9c279a8b2de6 100644 (file)
@@ -42,6 +42,7 @@ using std::distance;
 using std::pair;
 using std::list;
 using boost::shared_ptr;
+using boost::scoped_ptr;
 using boost::optional;
 
 int const DCPContentProperty::CAN_BE_PLAYED      = 600;
@@ -160,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
@@ -255,13 +254,19 @@ list<DCPTimePeriod>
 DCPContent::reels () const
 {
        list<DCPTimePeriod> p;
-       DCPDecoder decoder (shared_from_this(), false);
+       scoped_ptr<DCPDecoder> decoder;
+       try {
+               decoder.reset (new DCPDecoder (shared_from_this(), false));
+       } catch (...) {
+               /* Could not load the DCP; guess reels */
+               list<DCPTimePeriod> p;
+               p.push_back (DCPTimePeriod (position(), end()));
+               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());
+       BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder->reels()) {
+               DCPTime const to = from + DCPTime::from_frames (i->main_picture()->duration(), film()->video_frame_rate());
                p.push_back (DCPTimePeriod (from, to));
                from = to;
        }
@@ -283,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().
        */
@@ -297,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;
@@ -315,11 +317,27 @@ DCPContent::can_reference_video (list<string>& why_not) const
 bool
 DCPContent::can_reference_audio (list<string>& why_not) const
 {
+       DCPDecoder decoder (shared_from_this(), false);
+       BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder.reels()) {
+               if (!i->main_sound()) {
+                       why_not.push_back (_("The DCP does not have sound in all reels."));
+                       return false;
+               }
+       }
+
        return can_reference<AudioContent> (_("There is other audio content overlapping this DCP; remove it."), why_not);
 }
 
 bool
 DCPContent::can_reference_subtitle (list<string>& why_not) const
 {
+       DCPDecoder decoder (shared_from_this(), false);
+       BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder.reels()) {
+               if (!i->main_subtitle()) {
+                       why_not.push_back (_("The DCP does not have subtitles in all reels."));
+                       return false;
+               }
+       }
+
        return can_reference<SubtitleContent> (_("There is other subtitle content overlapping this DCP; remove it."), why_not);
 }