Tidying.
[libdcp.git] / src / reel.cc
index 89056cffef26f68db9b81a4bde791597ba999112..163164875555f18ef5be5948585e16ffaa224025 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
@@ -31,6 +31,7 @@
     files in the program, then also delete it here.
 */
 
+
 #include "reel.h"
 #include "util.h"
 #include "picture_asset.h"
 #include "reel_atmos_asset.h"
 #include "reel_closed_caption_asset.h"
 #include <libxml++/nodes/element.h>
-#include <boost/foreach.hpp>
 #include <stdint.h>
 
-/* Centos 6 does not have this */
-#ifndef INT64_MAX
-#define INT64_MAX 0x7fffffffffffffff
-#endif
 
 using std::string;
 using std::cout;
@@ -67,6 +63,7 @@ using std::dynamic_pointer_cast;
 using std::vector;
 using namespace dcp;
 
+
 Reel::Reel (std::shared_ptr<const cxml::Node> node)
        : Object (remove_urn_uuid (node->string_child ("Id")))
 {
@@ -74,27 +71,27 @@ Reel::Reel (std::shared_ptr<const cxml::Node> node)
 
        auto main_picture = asset_list->optional_node_child ("MainPicture");
        if (main_picture) {
-               _main_picture.reset (new ReelMonoPictureAsset (main_picture));
+               _main_picture = make_shared<ReelMonoPictureAsset>(main_picture);
        }
 
        auto main_stereoscopic_picture = asset_list->optional_node_child ("MainStereoscopicPicture");
        if (main_stereoscopic_picture) {
-               _main_picture.reset (new ReelStereoPictureAsset (main_stereoscopic_picture));
+               _main_picture = make_shared<ReelStereoPictureAsset>(main_stereoscopic_picture);
        }
 
        auto main_sound = asset_list->optional_node_child ("MainSound");
        if (main_sound) {
-               _main_sound.reset (new ReelSoundAsset (main_sound));
+               _main_sound = make_shared<ReelSoundAsset>(main_sound);
        }
 
        auto main_subtitle = asset_list->optional_node_child ("MainSubtitle");
        if (main_subtitle) {
-               _main_subtitle.reset (new ReelSubtitleAsset (main_subtitle));
+               _main_subtitle = make_shared<ReelSubtitleAsset>(main_subtitle);
        }
 
        auto main_markers = asset_list->optional_node_child ("MainMarkers");
        if (main_markers) {
-               _main_markers.reset (new ReelMarkersAsset (main_markers));
+               _main_markers = make_shared<ReelMarkersAsset>(main_markers);
        }
 
        /* XXX: it's not ideal that we silently tolerate Interop or SMPTE nodes here */
@@ -116,6 +113,7 @@ Reel::Reel (std::shared_ptr<const cxml::Node> node)
        node->done ();
 }
 
+
 xmlpp::Element *
 Reel::write_to_cpl (xmlpp::Element* node, Standard standard) const
 {
@@ -156,11 +154,12 @@ Reel::write_to_cpl (xmlpp::Element* node, Standard standard) const
        return asset_list;
 }
 
+
 bool
 Reel::equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandler note) const
 {
        if ((_main_picture && !other->_main_picture) || (!_main_picture && other->_main_picture)) {
-               note (DCP_ERROR, "Reel: picture assets differ");
+               note (NoteType::ERROR, "Reel: picture assets differ");
                return false;
        }
 
@@ -169,7 +168,7 @@ Reel::equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandle
        }
 
        if ((_main_sound && !other->_main_sound) || (!_main_sound && other->_main_sound)) {
-               note (DCP_ERROR, "Reel: sound assets differ");
+               note (NoteType::ERROR, "Reel: sound assets differ");
                return false;
        }
 
@@ -178,7 +177,7 @@ Reel::equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandle
        }
 
        if ((_main_subtitle && !other->_main_subtitle) || (!_main_subtitle && other->_main_subtitle)) {
-               note (DCP_ERROR, "Reel: subtitle assets differ");
+               note (NoteType::ERROR, "Reel: subtitle assets differ");
                return false;
        }
 
@@ -187,12 +186,12 @@ Reel::equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandle
        }
 
        if ((_main_markers && !other->_main_markers) || (!_main_markers && other->_main_markers)) {
-               note (DCP_ERROR, "Reel: one has markers and the other does not");
+               note (NoteType::ERROR, "Reel: one has markers and the other does not");
                return false;
        }
 
        if (_main_markers && !_main_markers->equals(other->_main_markers, opt, note)) {
-               note (DCP_ERROR, "Reel: marker assets differ");
+               note (NoteType::ERROR, "Reel: marker assets differ");
                return false;
        }
 
@@ -211,7 +210,7 @@ Reel::equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandle
        }
 
        if ((_atmos && !other->_atmos) || (!_atmos && other->_atmos)) {
-               note (DCP_ERROR, "Reel: atmos assets differ");
+               note (NoteType::ERROR, "Reel: atmos assets differ");
                return false;
        }
 
@@ -222,8 +221,9 @@ Reel::equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandle
        return true;
 }
 
+
 bool
-Reel::encrypted () const
+Reel::any_encrypted () const
 {
        auto ecc = false;
        for (auto i: _closed_captions) {
@@ -233,14 +233,35 @@ Reel::encrypted () const
        }
 
        return (
-               (_main_picture && _main_picture->encrypted ()) ||
-               (_main_sound && _main_sound->encrypted ()) ||
-               (_main_subtitle && _main_subtitle->encrypted ()) ||
+               (_main_picture && _main_picture->encrypted()) ||
+               (_main_sound && _main_sound->encrypted()) ||
+               (_main_subtitle && _main_subtitle->encrypted()) ||
                ecc ||
-               (_atmos && _atmos->encrypted ())
+               (_atmos && _atmos->encrypted())
                );
 }
 
+
+bool
+Reel::all_encrypted () const
+{
+       auto ecc = true;
+       for (auto i: _closed_captions) {
+               if (!i->encrypted()) {
+                       ecc = false;
+               }
+       }
+
+       return (
+               (!_main_picture || _main_picture->encrypted()) &&
+               (!_main_sound || _main_sound->encrypted()) &&
+               (!_main_subtitle || _main_subtitle->encrypted()) &&
+               ecc &&
+               (!_atmos || _atmos->encrypted())
+              );
+}
+
+
 void
 Reel::add (DecryptedKDM const & kdm)
 {
@@ -273,6 +294,7 @@ Reel::add (DecryptedKDM const & kdm)
        }
 }
 
+
 void
 Reel::add (shared_ptr<ReelAsset> asset)
 {
@@ -297,6 +319,7 @@ Reel::add (shared_ptr<ReelAsset> asset)
        }
 }
 
+
 vector<shared_ptr<ReelAsset>>
 Reel::assets () const
 {
@@ -317,19 +340,20 @@ Reel::assets () const
        return a;
 }
 
+
 void
 Reel::resolve_refs (vector<shared_ptr<Asset>> assets)
 {
        if (_main_picture) {
-               _main_picture->asset_ref().resolve (assets);
+               _main_picture->asset_ref().resolve(assets);
        }
 
        if (_main_sound) {
-               _main_sound->asset_ref().resolve (assets);
+               _main_sound->asset_ref().resolve(assets);
        }
 
        if (_main_subtitle) {
-               _main_subtitle->asset_ref().resolve (assets);
+               _main_subtitle->asset_ref().resolve(assets);
 
                /* Interop subtitle handling is all special cases */
                if (_main_subtitle->asset_ref().resolved()) {
@@ -357,6 +381,7 @@ Reel::resolve_refs (vector<shared_ptr<Asset>> assets)
        }
 }
 
+
 int64_t
 Reel::duration () const
 {