Fix crashes when static linking due to tricky lifetime crash
authorCarl Hetherington <cth@carlh.net>
Mon, 21 Sep 2020 20:33:43 +0000 (22:33 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 21 Sep 2020 22:06:21 +0000 (00:06 +0200)
management of ASDCP::DefaultSMPTEDict().

13 files changed:
src/cpl.cc
src/sound_asset.cc
src/sound_asset_writer.cc
src/util.cc
src/util.h
tools/dcpdecryptmxf.cc
tools/dcpdiff.cc
tools/dcpdumpsub.cc
tools/dcpinfo.cc
tools/dcpkdm.cc
tools/dcprecover.cc
tools/dcpthumb.cc
tools/dcpverify.cc

index 711c9e1bf72140a27b7ff39db08b97b85af8ccae..246ca21a2cd53f31c57843f7cb14b783ef7873da 100644 (file)
@@ -72,6 +72,7 @@ static string const mca_sub_descriptors_ns = "http://isdcf.com/ns/cplmd/mca";
 static string const smpte_395_ns = "http://www.smpte-ra.org/reg/395/2014/13/1/aaf";
 static string const smpte_335_ns = "http://www.smpte-ra.org/reg/335/2012";
 
+
 CPL::CPL (string annotation_text, ContentKind content_kind)
        /* default _content_title_text to annotation_text */
        : _issuer ("libdcp" LIBDCP_VERSION)
@@ -405,7 +406,7 @@ CPL::maybe_write_composition_metadata_asset (xmlpp::Element* node) const
                        shared_ptr<SoundAssetReader> reader = asset->start_read ();
                        ASDCP::MXF::SoundfieldGroupLabelSubDescriptor* soundfield;
                        ASDCP::Result_t r = reader->reader()->OP1aHeader().GetMDObjectByType(
-                               ASDCP::DefaultSMPTEDict().ul(ASDCP::MDD_SoundfieldGroupLabelSubDescriptor),
+                               asdcp_smpte_dict->ul(ASDCP::MDD_SoundfieldGroupLabelSubDescriptor),
                                reinterpret_cast<ASDCP::MXF::InterchangeObject**>(&soundfield)
                                );
                        if (KM_SUCCESS(r)) {
@@ -434,7 +435,7 @@ CPL::maybe_write_composition_metadata_asset (xmlpp::Element* node) const
 
                                list<ASDCP::MXF::InterchangeObject*> channels;
                                ASDCP::Result_t r = reader->reader()->OP1aHeader().GetMDObjectsByType(
-                                       ASDCP::DefaultSMPTEDict().ul(ASDCP::MDD_AudioChannelLabelSubDescriptor),
+                                       asdcp_smpte_dict->ul(ASDCP::MDD_AudioChannelLabelSubDescriptor),
                                        channels
                                        );
 
index 15626b9ae22a62a7a3dfa2d10ba82828a452de35..6752d9b1ac180a43bca43c52a93da2fc2f929505 100644 (file)
@@ -57,6 +57,7 @@ using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using namespace dcp;
 
+
 SoundAsset::SoundAsset (boost::filesystem::path file)
        : Asset (file)
        /* XXX: this is a fallback language, which will be used if we can't find the RFC5646SpokenLanguage
@@ -89,7 +90,7 @@ SoundAsset::SoundAsset (boost::filesystem::path file)
 
        ASDCP::MXF::SoundfieldGroupLabelSubDescriptor* soundfield;
        ASDCP::Result_t rr = reader.OP1aHeader().GetMDObjectByType(
-               ASDCP::DefaultSMPTEDict().ul(ASDCP::MDD_SoundfieldGroupLabelSubDescriptor),
+               asdcp_smpte_dict->ul(ASDCP::MDD_SoundfieldGroupLabelSubDescriptor),
                reinterpret_cast<ASDCP::MXF::InterchangeObject**>(&soundfield)
                );
 
index 3980dc62036ad9286d41df06dbd394fecbc60241..aaa35116b2130024d0feb41f5263c81395436219 100644 (file)
@@ -51,12 +51,6 @@ using std::vector;
 using namespace dcp;
 
 
-/* Some ASDCP objects store this as a *&, for reasons which are not
- * at all clear, so we have to keep this around forever.
- */
-static ASDCP::Dictionary const* smpte_dict = &ASDCP::DefaultSMPTEDict();
-
-
 struct SoundAssetWriter::ASDCPState
 {
        ASDCP::PCM::MXFWriter mxf_writer;
@@ -124,12 +118,12 @@ SoundAssetWriter::start ()
 
                ASDCP::MXF::WaveAudioDescriptor* essence_descriptor = 0;
                _state->mxf_writer.OP1aHeader().GetMDObjectByType(
-                       smpte_dict->ul(ASDCP::MDD_WaveAudioDescriptor), reinterpret_cast<ASDCP::MXF::InterchangeObject**>(&essence_descriptor)
+                       asdcp_smpte_dict->ul(ASDCP::MDD_WaveAudioDescriptor), reinterpret_cast<ASDCP::MXF::InterchangeObject**>(&essence_descriptor)
                        );
                DCP_ASSERT (essence_descriptor);
-               essence_descriptor->ChannelAssignment = smpte_dict->ul(ASDCP::MDD_DCAudioChannelCfg_MCA);
+               essence_descriptor->ChannelAssignment = asdcp_smpte_dict->ul(ASDCP::MDD_DCAudioChannelCfg_MCA);
 
-               ASDCP::MXF::SoundfieldGroupLabelSubDescriptor* soundfield = new ASDCP::MXF::SoundfieldGroupLabelSubDescriptor(smpte_dict);
+               ASDCP::MXF::SoundfieldGroupLabelSubDescriptor* soundfield = new ASDCP::MXF::SoundfieldGroupLabelSubDescriptor(asdcp_smpte_dict);
                GenRandomValue (soundfield->MCALinkID);
                soundfield->RFC5646SpokenLanguage = _asset->language().to_string();
 
@@ -138,25 +132,25 @@ SoundAssetWriter::start ()
                if (field == SEVEN_POINT_ONE) {
                        soundfield->MCATagSymbol = "sg71";
                        soundfield->MCATagName = "7.1DS";
-                       soundfield->MCALabelDictionaryID = smpte_dict->ul(ASDCP::MDD_DCAudioSoundfield_71);
+                       soundfield->MCALabelDictionaryID = asdcp_smpte_dict->ul(ASDCP::MDD_DCAudioSoundfield_71);
                } else {
                        soundfield->MCATagSymbol = "sg51";
                        soundfield->MCATagName = "5.1";
-                       soundfield->MCALabelDictionaryID = smpte_dict->ul(ASDCP::MDD_DCAudioSoundfield_51);
+                       soundfield->MCALabelDictionaryID = asdcp_smpte_dict->ul(ASDCP::MDD_DCAudioSoundfield_51);
                }
 
                _state->mxf_writer.OP1aHeader().AddChildObject(soundfield);
                essence_descriptor->SubDescriptors.push_back(soundfield->InstanceUID);
 
                BOOST_FOREACH (Channel i, _active_channels) {
-                       ASDCP::MXF::AudioChannelLabelSubDescriptor* channel = new ASDCP::MXF::AudioChannelLabelSubDescriptor(smpte_dict);
+                       ASDCP::MXF::AudioChannelLabelSubDescriptor* channel = new ASDCP::MXF::AudioChannelLabelSubDescriptor(asdcp_smpte_dict);
                        GenRandomValue (channel->MCALinkID);
                        channel->SoundfieldGroupLinkID = soundfield->MCALinkID;
                        channel->MCAChannelID = static_cast<int>(i) + 1;
                        channel->MCATagSymbol = "ch" + channel_to_mca_id(i, field);
                        channel->MCATagName = channel_to_mca_name(i, field);
                        channel->RFC5646SpokenLanguage = _asset->language().to_string();
-                       channel->MCALabelDictionaryID = channel_to_mca_universal_label(i, field, smpte_dict);
+                       channel->MCALabelDictionaryID = channel_to_mca_universal_label(i, field, asdcp_smpte_dict);
                        _state->mxf_writer.OP1aHeader().AddChildObject(channel);
                        essence_descriptor->SubDescriptors.push_back(channel->InstanceUID);
                }
index c7d090eaa016764411e8e44e935bc1a63d0a9c99..009d5baefe2ab21ded604d2d158a48071cd2c4b2 100644 (file)
@@ -76,6 +76,13 @@ using boost::function;
 using boost::algorithm::trim;
 using namespace dcp;
 
+
+/* Some ASDCP objects store this as a *&, for reasons which are not
+ * at all clear, so we have to keep this around forever.
+ */
+ASDCP::Dictionary const* dcp::asdcp_smpte_dict = 0;
+
+
 /** Create a UUID.
  *  @return UUID.
  */
@@ -164,7 +171,7 @@ dcp::empty_or_white_space (string s)
        return true;
 }
 
-/** Set up various bits that the library needs.  Should be called one
+/** Set up various bits that the library needs.  Should be called once
  *  by client applications.
  */
 void
@@ -189,6 +196,8 @@ dcp::init ()
        }
 
        OpenSSL_add_all_algorithms();
+
+       asdcp_smpte_dict = &ASDCP::DefaultSMPTEDict();
 }
 
 /** Decode a base64 string.  The base64 decode routine in KM_util.cpp
index a14d7364bbfbef381bf9b1e49cd05236534e22b1..959cbbcac13ef1b3c9f1a596d3e95d17047b255a 100644 (file)
@@ -82,6 +82,7 @@ extern void indent (xmlpp::Element* element, int initial);
 extern bool day_less_than_or_equal (LocalTime a, LocalTime b);
 extern bool day_greater_than_or_equal (LocalTime a, LocalTime b);
 extern std::string unique_string (std::list<std::string> existing, std::string base);
+extern ASDCP::Dictionary const* asdcp_smpte_dict;
 
 
 class ASDCPErrorSuspender
index 34ebf436878c163fe778fde49c0cfffd38bf20c3..a29986970a33b4410b1a7ac8568c903c0365c3ed 100644 (file)
@@ -66,6 +66,8 @@ help (string n)
 int
 main (int argc, char* argv[])
 {
+       dcp::init ();
+
        optional<boost::filesystem::path> output_file;
        optional<boost::filesystem::path> kdm_file;
        optional<boost::filesystem::path> private_key_file;
index 976a29193b31f60ce30fb102c9ebf82d173d604b..80d4b049bed4032ba88389540db4a690a685e607 100644 (file)
@@ -119,6 +119,8 @@ load_dcp (boost::filesystem::path path, bool ignore_missing_assets, optional<str
 int
 main (int argc, char* argv[])
 {
+       dcp::init ();
+
        EqualityOptions options;
        options.max_mean_pixel_error = 5;
        options.max_std_dev_pixel_error = 5;
index d9f11b478e7ab7da2e75e8d57eb9bc16ff134f8a..6f0c5f6f3c53c0be01c8866e67b849d8d324ac0c 100644 (file)
@@ -61,6 +61,8 @@ help (string n)
 int
 main (int argc, char* argv[])
 {
+       dcp::init ();
+
        bool extract_fonts = true;
        optional<boost::filesystem::path> kdm_file;
        optional<boost::filesystem::path> private_key_file;
index 38e43eb1425229b47e2fb0730b457b3e35deb7dd..3afff7f093c5f66e64589d23999630c27208119e 100644 (file)
@@ -283,6 +283,8 @@ main_subtitle (vector<string> const& only, shared_ptr<Reel> reel, bool list_subt
 int
 main (int argc, char* argv[])
 {
+       dcp::init ();
+
        bool subtitles = false;
        bool picture = false;
        bool decompress = false;
index c34454be7cd835df74a4820d40a5fcefd84b32ee..ef889f481e13061d2d9ee9163265a0f3d2b2c233 100644 (file)
@@ -64,6 +64,8 @@ int
 main (int argc, char* argv[])
 try
 {
+       dcp::init ();
+
        optional<boost::filesystem::path> private_key_file;
 
        int option_index = 0;
index caf0e0fe753fca1e49067a1236c44bd2efac7cb0..65240ae85227a918fbb0194e501d3e36305e61b2 100644 (file)
@@ -65,6 +65,8 @@ void progress (float f)
 int
 main (int argc, char* argv[])
 {
+       dcp::init ();
+
        int option_index = 0;
        optional<boost::filesystem::path> output;
        while (true) {
index 7d90c2ef72e69a7695ba706083918da7956eb281..2adccfd06cafb6bd2eb599f563c961c62cefe96d 100644 (file)
@@ -53,6 +53,8 @@ help (string n)
 int
 main (int argc, char* argv[])
 {
+       dcp::init ();
+
        int option_index = 0;
        while (true) {
                struct option long_options[] = {
index 968c4710cd4a76151f5acfc8060b15ccbf00bcc4..c484516e54c5ebe8f42c63631eaf92ef9d33a2b8 100644 (file)
@@ -83,6 +83,8 @@ progress ()
 int
 main (int argc, char* argv[])
 {
+       dcp::init ();
+
        bool ignore_missing_assets = false;
        bool quiet = false;