Fixes for new libdcp with multiple content versions.
[dcpomatic.git] / src / lib / dcp_examiner.cc
index 9bf401125dda6dea75e3a880541603256588e079..27eb74a5d5231e559cc5856ff78040d105e8c786 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -23,6 +23,7 @@
 #include "exceptions.h"
 #include "image.h"
 #include "config.h"
+#include "util.h"
 #include <dcp/dcp.h>
 #include <dcp/decrypted_kdm.h>
 #include <dcp/cpl.h>
 #include <dcp/sound_asset.h>
 #include <dcp/sound_asset_reader.h>
 #include <dcp/subtitle_asset.h>
+#include <dcp/reel_atmos_asset.h>
 #include <dcp/reel_subtitle_asset.h>
 #include <dcp/reel_closed_caption_asset.h>
+#include <dcp/reel_markers_asset.h>
 #include <dcp/sound_asset.h>
 #include <boost/foreach.hpp>
 #include <iostream>
@@ -49,6 +52,7 @@
 using std::list;
 using std::cout;
 using std::runtime_error;
+using std::map;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 
@@ -62,6 +66,8 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
        , _needs_assets (false)
        , _kdm_valid (false)
        , _three_d (false)
+       , _has_atmos (false)
+       , _atmos_length (0)
 {
        shared_ptr<dcp::CPL> cpl;
 
@@ -93,6 +99,9 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
                                if (j->main_subtitle() && !j->main_subtitle()->asset_ref().resolved()) {
                                        ++unsatisfied;
                                }
+                               if (j->atmos() && !j->atmos()->asset_ref().resolved()) {
+                                       ++unsatisfied;
+                               }
                        }
 
                        if (unsatisfied < least_unsatisfied) {
@@ -181,6 +190,21 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
                        }
 
                        _text_count[TEXT_CLOSED_CAPTION]++;
+                       _dcp_text_tracks.push_back (DCPTextTrack(j->annotation_text(), j->language().get_value_or(_("Unknown"))));
+               }
+
+               if (i->main_markers ()) {
+                       map<dcp::Marker, dcp::Time> rm = i->main_markers()->get();
+                       _markers.insert (rm.begin(), rm.end());
+               }
+
+               if (i->atmos()) {
+                       _has_atmos = true;
+                       _atmos_length += i->atmos()->actual_duration();
+                       if (_atmos_edit_rate != dcp::Fraction()) {
+                               DCPOMATIC_ASSERT (i->atmos()->edit_rate() == _atmos_edit_rate);
+                       }
+                       _atmos_edit_rate = i->atmos()->edit_rate();
                }
 
                if (i->main_picture()) {
@@ -191,6 +215,8 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
                        _reel_lengths.push_back (i->main_subtitle()->actual_duration());
                } else if (!i->closed_captions().empty()) {
                        _reel_lengths.push_back (i->closed_captions().front()->actual_duration());
+               } else if (!i->atmos()) {
+                       _reel_lengths.push_back (i->atmos()->actual_duration());
                }
        }
 
@@ -218,6 +244,10 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
                        if (i->main_subtitle()) {
                                i->main_subtitle()->asset()->subtitles ();
                        }
+
+                       if (i->atmos()) {
+                               i->atmos()->asset()->start_read()->get_frame(0);
+                       }
                }
        } catch (dcp::ReadError& e) {
                _kdm_valid = false;
@@ -229,6 +259,10 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
        _standard = cpl->standard().get();
        _three_d = !cpl->reels().empty() && cpl->reels().front()->main_picture() &&
                dynamic_pointer_cast<dcp::StereoPictureAsset> (cpl->reels().front()->main_picture()->asset());
+       _ratings = cpl->ratings();
+       BOOST_FOREACH (dcp::ContentVersion i, cpl->content_versions()) {
+               _content_versions.push_back (i.label_text);
+       }
 
        _cpl = cpl->id ();
 }