Fix nonfunctional send-problem-report.
[dcpomatic.git] / src / lib / dcp_content.cc
index cb9dcf53d6dc184caaa47f098fb3954b2a3eec8a..f65aaec7e08511ccc6e3ffa05a8d9c279a8b2de6 100644 (file)
 #include "job.h"
 #include "film.h"
 #include "config.h"
+#include "overlaps.h"
 #include "compose.hpp"
+#include "dcp_decoder.h"
 #include <dcp/dcp.h>
 #include <dcp/exceptions.h>
+#include <dcp/reel_picture_asset.h>
+#include <dcp/reel.h>
 #include <libxml++/libxml++.h>
+#include <boost/foreach.hpp>
 #include <iterator>
 #include <iostream>
 
@@ -37,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;
@@ -155,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
@@ -245,3 +249,95 @@ DCPContent::set_reference_subtitle (bool r)
 
        signal_changed (DCPContentProperty::REFERENCE_SUBTITLE);
 }
+
+list<DCPTimePeriod>
+DCPContent::reels () const
+{
+       list<DCPTimePeriod> p;
+       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;
+       }
+
+       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());
+               p.push_back (DCPTimePeriod (from, to));
+               from = to;
+       }
+
+       return p;
+}
+
+list<DCPTime>
+DCPContent::reel_split_points () const
+{
+       list<DCPTime> s;
+       BOOST_FOREACH (DCPTimePeriod i, reels()) {
+               s.push_back (i.from);
+       }
+       return s;
+}
+
+template <class T>
+bool
+DCPContent::can_reference (string overlapping, list<string>& why_not) const
+{
+       list<DCPTimePeriod> const fr = film()->reels ();
+       /* fr must contain reels().  It can also contain other reels, but it must at
+          least contain reels().
+       */
+       BOOST_FOREACH (DCPTimePeriod i, reels()) {
+               if (find (fr.begin(), fr.end(), i) == fr.end ()) {
+                       why_not.push_back (_("Reel lengths in the project differ from those in the DCP; set the reel mode to `split by video content'."));
+                       return false;
+               }
+       }
+
+       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;
+       }
+
+       return true;
+}
+
+bool
+DCPContent::can_reference_video (list<string>& why_not) const
+{
+       return can_reference<VideoContent> (_("There is other video content overlapping this DCP; remove it."), why_not);
+}
+
+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);
+}