Fix content properties (#1428).
[dcpomatic.git] / src / lib / dcp_content.cc
index 3110f93ad5eb6b61abf18ceb1e752da5f7647b7b..8a2e2050d295547320ca9f4def69aee4eb3fb268 100644 (file)
@@ -29,6 +29,7 @@
 #include "compose.hpp"
 #include "dcp_decoder.h"
 #include "log.h"
+#include "dcpomatic_log.h"
 #include "text_content.h"
 #include <dcp/dcp.h>
 #include <dcp/raw_convert.h>
@@ -64,8 +65,6 @@ int const DCPContentProperty::NAME               = 605;
 int const DCPContentProperty::TEXTS              = 606;
 int const DCPContentProperty::CPL                = 607;
 
-#define LOG_GENERAL(...) dcpomatic_log->log(String::compose(__VA_ARGS__), LogEntry::TYPE_GENERAL);
-
 DCPContent::DCPContent (boost::filesystem::path p)
        : _encrypted (false)
        , _needs_assets (false)
@@ -151,16 +150,7 @@ DCPContent::DCPContent (cxml::ConstNodePtr node, int version)
 void
 DCPContent::read_directory (boost::filesystem::path p)
 {
-       LOG_GENERAL ("DCPContent::read_directory reads %1", p.string());
-       for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
-               if (boost::filesystem::is_regular_file (i->path())) {
-                       LOG_GENERAL ("Inside there's regular file %1", i->path().string());
-                       add_path (i->path());
-               } else if (boost::filesystem::is_directory (i->path ())) {
-                       LOG_GENERAL ("Inside there's directory %1", i->path().string());
-                       read_directory (i->path());
-               }
-       }
+       read_sub_directory (p);
 
        bool have_assetmap = false;
        BOOST_FOREACH (boost::filesystem::path i, paths()) {
@@ -174,6 +164,21 @@ DCPContent::read_directory (boost::filesystem::path p)
        }
 }
 
+void
+DCPContent::read_sub_directory (boost::filesystem::path p)
+{
+       LOG_GENERAL ("DCPContent::read_sub_directory reads %1", p.string());
+       for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
+               if (boost::filesystem::is_regular_file (i->path())) {
+                       LOG_GENERAL ("Inside there's regular file %1", i->path().string());
+                       add_path (i->path());
+               } else if (boost::filesystem::is_directory (i->path ())) {
+                       LOG_GENERAL ("Inside there's directory %1", i->path().string());
+                       read_sub_directory (i->path());
+               }
+       }
+}
+
 void
 DCPContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
 {
@@ -213,7 +218,7 @@ DCPContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
                AudioStreamPtr as (new AudioStream (examiner->audio_frame_rate(), examiner->audio_length(), examiner->audio_channels()));
                audio->set_stream (as);
                AudioMapping m = as->mapping ();
-               film->make_audio_mapping_default (m);
+               m.make_default (film ? film->audio_processor() : 0);
                as->set_mapping (m);
        }
 
@@ -346,6 +351,15 @@ DCPContent::full_length (shared_ptr<const Film> film) const
        return DCPTime::from_frames (llrint(video->length() * frc.factor()), film->video_frame_rate());
 }
 
+DCPTime
+DCPContent::approximate_length () const
+{
+       if (!video) {
+               return DCPTime();
+       }
+       return DCPTime::from_frames (video->length(), 24);
+}
+
 string
 DCPContent::identifier () const
 {
@@ -407,7 +421,7 @@ DCPContent::directories () const
 void
 DCPContent::add_properties (shared_ptr<const Film> film, list<UserProperty>& p) const
 {
-       Content::add_properties (p);
+       Content::add_properties (film, p);
        if (video) {
                video->add_properties (p);
        }