Write MCA tags based on the specified sound field.
[libdcp.git] / src / reel_closed_caption_asset.cc
index 4fb729c679fa47b507c1c25b50c59d9347d31ab5..1cb97cb01c64df8a34498c249baf0b0622620c8e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
     files in the program, then also delete it here.
 */
 
+
 /** @file  src/reel_closed_caption_asset.cc
- *  @brief ReelClosedCaptionAsset class.
+ *  @brief ReelClosedCaptionAsset class
  */
 
+
 #include "subtitle_asset.h"
 #include "reel_closed_caption_asset.h"
 #include "smpte_subtitle_asset.h"
 #include "dcp_assert.h"
 #include <libxml++/libxml++.h>
 
+
 using std::string;
 using std::pair;
 using std::make_pair;
-using boost::shared_ptr;
-using boost::dynamic_pointer_cast;
+using std::shared_ptr;
+using std::dynamic_pointer_cast;
 using boost::optional;
 using namespace dcp;
 
-ReelClosedCaptionAsset::ReelClosedCaptionAsset (boost::shared_ptr<SubtitleAsset> asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
-       : ReelAsset (asset, edit_rate, intrinsic_duration, entry_point)
-       , ReelMXF (dynamic_pointer_cast<SMPTESubtitleAsset>(asset) ? dynamic_pointer_cast<SMPTESubtitleAsset>(asset)->key_id() : optional<string>())
+
+ReelClosedCaptionAsset::ReelClosedCaptionAsset (std::shared_ptr<SubtitleAsset> asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
+       : ReelAsset (asset->id(), edit_rate, intrinsic_duration, entry_point)
+       , ReelFileAsset (asset, dynamic_pointer_cast<SMPTESubtitleAsset>(asset) ? dynamic_pointer_cast<SMPTESubtitleAsset>(asset)->key_id() : optional<string>())
 {
 
 }
 
-ReelClosedCaptionAsset::ReelClosedCaptionAsset (boost::shared_ptr<const cxml::Node> node)
+
+ReelClosedCaptionAsset::ReelClosedCaptionAsset (std::shared_ptr<const cxml::Node> node)
        : ReelAsset (node)
-       , ReelMXF (node)
+       , ReelFileAsset (node)
 {
-       node->ignore_child ("Language");
+       _language = node->optional_string_child ("Language");
        node->done ();
 }
 
+
 string
 ReelClosedCaptionAsset::cpl_node_name (Standard standard) const
 {
        switch (standard) {
-       case INTEROP:
+       case Standard::INTEROP:
                return "cc-cpl:MainClosedCaption";
-       case SMPTE:
+       case Standard::SMPTE:
                return "tt:ClosedCaption";
        }
 
        DCP_ASSERT (false);
 }
 
+
 pair<string, string>
 ReelClosedCaptionAsset::cpl_node_namespace (Standard standard) const
 {
        switch (standard) {
-       case INTEROP:
+       case Standard::INTEROP:
                return make_pair ("http://www.digicine.com/PROTO-ASDCP-CC-CPL-20070926#", "cc-cpl");
-       case SMPTE:
+       case Standard::SMPTE:
                return make_pair ("http://www.smpte-ra.org/schemas/429-12/2008/TT", "tt");
        }
 
        DCP_ASSERT (false);
 }
 
+
 string
 ReelClosedCaptionAsset::key_type () const
 {
        return "MDSK";
 }
 
-void
+
+xmlpp::Node *
 ReelClosedCaptionAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
 {
-       ReelAsset::write_to_cpl (node, standard);
-
-        if (key_id ()) {
-               /* Find our main tag */
-               xmlpp::Node* ms = find_child (node, cpl_node_name (standard));
-               /* Find <Hash> */
-               xmlpp::Node* hash = find_child (ms, "Hash");
-               ms->add_child_before (hash, "KeyId")->add_child_text ("urn:uuid:" + key_id().get ());
+       auto asset = write_to_cpl_asset (node, standard, hash());
+       write_to_cpl_mxf (asset);
+
+       if (_language) {
+               switch (standard) {
+               case Standard::INTEROP:
+                       asset->add_child("Language")->add_child_text(*_language);
+                       break;
+               case Standard::SMPTE:
+                       asset->add_child("Language", "tt")->add_child_text(*_language);
+                       break;
+               }
        }
+
+       return asset;
+}
+
+
+bool
+ReelClosedCaptionAsset::equals (shared_ptr<const ReelClosedCaptionAsset> other, EqualityOptions opt, NoteHandler note) const
+{
+       if (!asset_equals (other, opt, note)) {
+               return false;
+       }
+       if (!mxf_equals (other, opt, note)) {
+               return false;
+       }
+
+       return true;
 }