Fix build on old GCC.
[libdcp.git] / src / reel.cc
index 74107ed05e883e5af051c2522122e67ca4d625b5..e99f7140d809cb568befc96467da0daadb7e0bc4 100644 (file)
 #include "reel_mono_picture_asset.h"
 #include "reel_stereo_picture_asset.h"
 #include "reel_sound_asset.h"
+#include "reel_interop_closed_caption_asset.h"
+#include "reel_interop_subtitle_asset.h"
+#include "reel_smpte_closed_caption_asset.h"
+#include "reel_smpte_subtitle_asset.h"
 #include "reel_subtitle_asset.h"
 #include "reel_markers_asset.h"
 #include "decrypted_kdm_key.h"
@@ -69,7 +73,7 @@ using std::vector;
 using namespace dcp;
 
 
-Reel::Reel (std::shared_ptr<const cxml::Node> node)
+Reel::Reel (std::shared_ptr<const cxml::Node> node, dcp::Standard standard)
        : Object (remove_urn_uuid (node->string_child ("Id")))
 {
        auto asset_list = node->node_child ("AssetList");
@@ -91,7 +95,14 @@ Reel::Reel (std::shared_ptr<const cxml::Node> node)
 
        auto main_subtitle = asset_list->optional_node_child ("MainSubtitle");
        if (main_subtitle) {
-               _main_subtitle = make_shared<ReelSubtitleAsset>(main_subtitle);
+               switch (standard) {
+                       case Standard::INTEROP:
+                               _main_subtitle = make_shared<ReelInteropSubtitleAsset>(main_subtitle);
+                               break;
+                       case Standard::SMPTE:
+                               _main_subtitle = make_shared<ReelSMPTESubtitleAsset>(main_subtitle);
+                               break;
+               }
        }
 
        auto main_markers = asset_list->optional_node_child ("MainMarkers");
@@ -106,7 +117,14 @@ Reel::Reel (std::shared_ptr<const cxml::Node> node)
                closed_captions = asset_list->node_children ("ClosedCaption");
        }
        for (auto i: closed_captions) {
-               _closed_captions.push_back (make_shared<ReelClosedCaptionAsset>(i));
+               switch (standard) {
+                       case Standard::INTEROP:
+                               _closed_captions.push_back (make_shared<ReelInteropClosedCaptionAsset>(i));
+                               break;
+                       case Standard::SMPTE:
+                               _closed_captions.push_back (make_shared<ReelSMPTEClosedCaptionAsset>(i));
+                               break;
+               }
        }
 
        auto atmos = asset_list->optional_node_child ("AuxData");
@@ -186,7 +204,31 @@ Reel::equals (std::shared_ptr<const Reel> other, EqualityOptions opt, NoteHandle
                return false;
        }
 
-       if (_main_subtitle && !_main_subtitle->equals (other->_main_subtitle, opt, note)) {
+       bool same_type = false;
+
+       {
+               auto interop = dynamic_pointer_cast<ReelInteropSubtitleAsset>(_main_subtitle);
+               auto interop_other = dynamic_pointer_cast<ReelInteropSubtitleAsset>(other->_main_subtitle);
+               if (interop && interop_other) {
+                       same_type = true;
+                       if (!interop->equals(interop_other, opt, note)) {
+                               return false;
+                       }
+               }
+       }
+
+       {
+               auto smpte = dynamic_pointer_cast<ReelSMPTESubtitleAsset>(_main_subtitle);
+               auto smpte_other = dynamic_pointer_cast<ReelSMPTESubtitleAsset>(other->_main_subtitle);
+               if (smpte && smpte_other) {
+                       same_type = true;
+                       if (!smpte->equals(smpte_other, opt, note)) {
+                               return false;
+                       }
+               }
+       }
+
+       if ((_main_subtitle || other->_main_subtitle) && !same_type) {
                return false;
        }
 
@@ -279,18 +321,16 @@ Reel::add (DecryptedKDM const & kdm)
                if (_main_sound && i.id() == _main_sound->key_id()) {
                        _main_sound->asset()->set_key (i.key());
                }
-               if (_main_subtitle && i.id() == _main_subtitle->key_id()) {
-                       shared_ptr<SMPTESubtitleAsset> s = dynamic_pointer_cast<SMPTESubtitleAsset> (_main_subtitle->asset());
-                       if (s) {
-                               s->set_key (i.key());
+               if (_main_subtitle) {
+                       auto smpte = dynamic_pointer_cast<ReelSMPTESubtitleAsset>(_main_picture);
+                       if (smpte && i.id() == smpte->key_id()) {
+                               smpte->smpte_asset()->set_key(i.key());
                        }
                }
                for (auto j: _closed_captions) {
-                       if (i.id() == j->key_id()) {
-                               auto s = dynamic_pointer_cast<SMPTESubtitleAsset> (j->asset());
-                               if (s) {
-                                       s->set_key (i.key());
-                               }
+                       auto smpte = dynamic_pointer_cast<ReelSMPTESubtitleAsset>(j);
+                       if (smpte && i.id() == smpte->key_id()) {
+                               smpte->smpte_asset()->set_key(i.key());
                        }
                }
                if (_atmos && i.id() == _atmos->key_id()) {