summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-12-16 17:45:46 +0100
committerCarl Hetherington <cth@carlh.net>2025-12-18 01:10:32 +0100
commitc3c127e0bdb988696d16f47ea8080df3eff38420 (patch)
treeecdff8d299152eef491f1946e6ccb4f6d9cf8e71 /src
parent45ed3bf55175a8555123b320b366efb69b1ba629 (diff)
Add can_be_read() to ReelFileAsset and subclasses.
Diffstat (limited to 'src')
-rw-r--r--src/atmos_asset.cc22
-rw-r--r--src/atmos_asset.h2
-rw-r--r--src/mono_j2k_picture_asset.cc22
-rw-r--r--src/mono_j2k_picture_asset.h2
-rw-r--r--src/mono_mpeg2_picture_asset.cc24
-rw-r--r--src/mono_mpeg2_picture_asset.h2
-rw-r--r--src/mxf.cc7
-rw-r--r--src/mxf.h2
-rw-r--r--src/reel_atmos_asset.cc12
-rw-r--r--src/reel_atmos_asset.h2
-rw-r--r--src/reel_file_asset.cc7
-rw-r--r--src/reel_file_asset.h1
-rw-r--r--src/reel_mono_picture_asset.cc14
-rw-r--r--src/reel_mono_picture_asset.h2
-rw-r--r--src/reel_smpte_text_asset.cc11
-rw-r--r--src/reel_smpte_text_asset.h2
-rw-r--r--src/reel_sound_asset.cc12
-rw-r--r--src/reel_sound_asset.h2
-rw-r--r--src/reel_stereo_picture_asset.cc17
-rw-r--r--src/reel_stereo_picture_asset.h2
-rw-r--r--src/smpte_text_asset.cc21
-rw-r--r--src/smpte_text_asset.h2
-rw-r--r--src/sound_asset.cc21
-rw-r--r--src/sound_asset.h2
-rw-r--r--src/stereo_j2k_picture_asset.cc22
-rw-r--r--src/stereo_j2k_picture_asset.h2
26 files changed, 234 insertions, 3 deletions
diff --git a/src/atmos_asset.cc b/src/atmos_asset.cc
index 09a22c1e..9c4b1c80 100644
--- a/src/atmos_asset.cc
+++ b/src/atmos_asset.cc
@@ -122,3 +122,25 @@ AtmosAsset::start_write (boost::filesystem::path file)
/* Can't use make_shared here since the constructor is protected */
return shared_ptr<AtmosAssetWriter>(new AtmosAssetWriter(this, file));
}
+
+
+bool
+AtmosAsset::can_be_read() const
+{
+ if (!MXF::can_be_read()) {
+ return false;
+ }
+
+ try {
+ auto reader = start_read();
+ reader->set_check_hmac(false);
+ reader->get_frame(0);
+ } catch (dcp::ReadError&) {
+ return false;
+ } catch (dcp::MiscError&) {
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/src/atmos_asset.h b/src/atmos_asset.h
index a682ae60..9fcd359f 100644
--- a/src/atmos_asset.h
+++ b/src/atmos_asset.h
@@ -61,6 +61,8 @@ public:
AtmosAsset (Fraction edit_rate, int first_frame, int max_channel_count, int max_object_count, int atmos_version);
explicit AtmosAsset (boost::filesystem::path file);
+ bool can_be_read() const override;
+
std::shared_ptr<AtmosAssetWriter> start_write (boost::filesystem::path file);
std::shared_ptr<AtmosAssetReader> start_read () const;
diff --git a/src/mono_j2k_picture_asset.cc b/src/mono_j2k_picture_asset.cc
index b1f311d6..4a8a3219 100644
--- a/src/mono_j2k_picture_asset.cc
+++ b/src/mono_j2k_picture_asset.cc
@@ -207,3 +207,25 @@ MonoJ2KPictureAsset::cpl_node_name () const
{
return "MainPicture";
}
+
+
+bool
+MonoJ2KPictureAsset::can_be_read() const
+{
+ if (!MXF::can_be_read()) {
+ return false;
+ }
+
+ try {
+ auto reader = start_read();
+ reader->set_check_hmac(false);
+ reader->get_frame(0)->xyz_image();
+ } catch (dcp::ReadError&) {
+ return false;
+ } catch (dcp::MiscError&) {
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/src/mono_j2k_picture_asset.h b/src/mono_j2k_picture_asset.h
index d716b8ff..f790e543 100644
--- a/src/mono_j2k_picture_asset.h
+++ b/src/mono_j2k_picture_asset.h
@@ -68,6 +68,8 @@ public:
*/
MonoJ2KPictureAsset(Fraction edit_rate, Standard standard);
+ bool can_be_read() const override;
+
/** Start a progressive write to a MonoJ2KPictureAsset.
* @path file File to write to.
* @path behaviour OVERWRITE_EXISTING to overwrite and potentially add to an existing file
diff --git a/src/mono_mpeg2_picture_asset.cc b/src/mono_mpeg2_picture_asset.cc
index 380da0fe..9a879f0b 100644
--- a/src/mono_mpeg2_picture_asset.cc
+++ b/src/mono_mpeg2_picture_asset.cc
@@ -36,6 +36,7 @@
#include "mono_mpeg2_picture_asset.h"
#include "mono_mpeg2_picture_asset_reader.h"
#include "mono_mpeg2_picture_asset_writer.h"
+#include "mpeg2_transcode.h"
#include <asdcp/AS_DCP.h>
@@ -84,3 +85,26 @@ MonoMPEG2PictureAsset::start_write(boost::filesystem::path file, Behaviour behav
/* Can't use make_shared here as the MonoJ2KPictureAssetWriter constructor is private */
return shared_ptr<MonoMPEG2PictureAssetWriter>(new MonoMPEG2PictureAssetWriter(this, file, behaviour == Behaviour::OVERWRITE_EXISTING));
}
+
+
+bool
+MonoMPEG2PictureAsset::can_be_read() const
+{
+ if (!MXF::can_be_read()) {
+ return false;
+ }
+
+ try {
+ auto reader = start_read();
+ reader->set_check_hmac(false);
+ dcp::MPEG2Decompressor decompressor;
+ decompressor.decompress_frame(reader->get_frame(0));
+ } catch (dcp::ReadError&) {
+ return false;
+ } catch (dcp::MiscError&) {
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/src/mono_mpeg2_picture_asset.h b/src/mono_mpeg2_picture_asset.h
index 8ef3653e..dc2637e7 100644
--- a/src/mono_mpeg2_picture_asset.h
+++ b/src/mono_mpeg2_picture_asset.h
@@ -61,6 +61,8 @@ public:
explicit MonoMPEG2PictureAsset(boost::filesystem::path file);
+ bool can_be_read() const override;
+
std::shared_ptr<MPEG2PictureAssetWriter> start_write(boost::filesystem::path file, Behaviour behaviour) override;
std::shared_ptr<MonoMPEG2PictureAssetReader> start_read() const;
};
diff --git a/src/mxf.cc b/src/mxf.cc
index 1154b80d..60ef5552 100644
--- a/src/mxf.cc
+++ b/src/mxf.cc
@@ -146,3 +146,10 @@ MXF::read_writer_info (ASDCP::WriterInfo const & info)
Kumu::bin2UUIDhex (info.AssetUUID, ASDCP::UUIDlen, buffer, sizeof (buffer));
return buffer;
}
+
+
+bool
+MXF::can_be_read() const
+{
+ return !encrypted() || key();
+}
diff --git a/src/mxf.h b/src/mxf.h
index ad9e39ed..933e7afb 100644
--- a/src/mxf.h
+++ b/src/mxf.h
@@ -76,6 +76,8 @@ public:
MXF (Standard standard);
virtual ~MXF () {}
+ virtual bool can_be_read() const;
+
/** @return true if the data is encrypted */
bool encrypted () const {
return static_cast<bool>(_key_id);
diff --git a/src/reel_atmos_asset.cc b/src/reel_atmos_asset.cc
index fcecb548..ae7be33a 100644
--- a/src/reel_atmos_asset.cc
+++ b/src/reel_atmos_asset.cc
@@ -104,3 +104,15 @@ ReelAtmosAsset::equals(shared_ptr<const ReelAtmosAsset> other, EqualityOptions c
return true;
}
+
+
+bool
+ReelAtmosAsset::can_be_read() const
+{
+ if (!ReelFileAsset::can_be_read()) {
+ return false;
+ }
+
+ return asset()->can_be_read();
+}
+
diff --git a/src/reel_atmos_asset.h b/src/reel_atmos_asset.h
index ab18d1ab..ed525bae 100644
--- a/src/reel_atmos_asset.h
+++ b/src/reel_atmos_asset.h
@@ -60,6 +60,8 @@ public:
ReelAtmosAsset (std::shared_ptr<AtmosAsset> asset, int64_t entry_point);
explicit ReelAtmosAsset (std::shared_ptr<const cxml::Node>);
+ bool can_be_read() const override;
+
std::shared_ptr<const AtmosAsset> asset () const {
return asset_of_type<const AtmosAsset>();
}
diff --git a/src/reel_file_asset.cc b/src/reel_file_asset.cc
index 8fed8012..ad534ebd 100644
--- a/src/reel_file_asset.cc
+++ b/src/reel_file_asset.cc
@@ -107,3 +107,10 @@ ReelFileAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const
return asset;
}
+
+bool
+ReelFileAsset::can_be_read() const
+{
+ return asset_ref().resolved();
+}
+
diff --git a/src/reel_file_asset.h b/src/reel_file_asset.h
index 48fdf215..2412ac2b 100644
--- a/src/reel_file_asset.h
+++ b/src/reel_file_asset.h
@@ -57,6 +57,7 @@ public:
explicit ReelFileAsset (std::shared_ptr<const cxml::Node> node);
virtual xmlpp::Element* write_to_cpl(xmlpp::Element* node, Standard standard) const override;
+ virtual bool can_be_read() const;
/** @return a Ref to our actual asset */
Ref const & asset_ref () const {
diff --git a/src/reel_mono_picture_asset.cc b/src/reel_mono_picture_asset.cc
index 5dbf85d2..9cbeb7e1 100644
--- a/src/reel_mono_picture_asset.cc
+++ b/src/reel_mono_picture_asset.cc
@@ -42,8 +42,9 @@
#include <libcxml/cxml.h>
-using std::string;
+using std::dynamic_pointer_cast;
using std::shared_ptr;
+using std::string;
using namespace dcp;
@@ -66,3 +67,14 @@ ReelMonoPictureAsset::cpl_node_name() const
{
return "MainPicture";
}
+
+
+bool
+ReelMonoPictureAsset::can_be_read() const
+{
+ if (!ReelFileAsset::can_be_read()) {
+ return false;
+ }
+
+ return asset()->can_be_read();
+}
diff --git a/src/reel_mono_picture_asset.h b/src/reel_mono_picture_asset.h
index 0c468e0e..29df2d14 100644
--- a/src/reel_mono_picture_asset.h
+++ b/src/reel_mono_picture_asset.h
@@ -61,6 +61,8 @@ public:
ReelMonoPictureAsset(std::shared_ptr<PictureAsset> asset, int64_t entry_point);
explicit ReelMonoPictureAsset (std::shared_ptr<const cxml::Node>);
+ bool can_be_read() const override;
+
/** @return the MonoJ2KPictureAsset that this object refers to, if applicable */
std::shared_ptr<const MonoJ2KPictureAsset> mono_j2k_asset() const {
return asset_of_type<const MonoJ2KPictureAsset>();
diff --git a/src/reel_smpte_text_asset.cc b/src/reel_smpte_text_asset.cc
index b1ce34cb..30a4d443 100644
--- a/src/reel_smpte_text_asset.cc
+++ b/src/reel_smpte_text_asset.cc
@@ -116,3 +116,14 @@ ReelSMPTETextAsset::write_to_cpl(xmlpp::Element* node, Standard standard) const
}
+
+bool
+ReelSMPTETextAsset::can_be_read() const
+{
+ if (!ReelFileAsset::can_be_read()) {
+ return false;
+ }
+
+ return smpte_asset()->can_be_read();
+}
+
diff --git a/src/reel_smpte_text_asset.h b/src/reel_smpte_text_asset.h
index b3c2f655..68459c30 100644
--- a/src/reel_smpte_text_asset.h
+++ b/src/reel_smpte_text_asset.h
@@ -56,6 +56,8 @@ public:
ReelSMPTETextAsset(TextType type, std::shared_ptr<SMPTETextAsset> asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point);
explicit ReelSMPTETextAsset(std::shared_ptr<const cxml::Node>);
+ bool can_be_read() const override;
+
std::shared_ptr<const SMPTETextAsset> smpte_asset() const {
return asset_of_type<const SMPTETextAsset>();
}
diff --git a/src/reel_sound_asset.cc b/src/reel_sound_asset.cc
index dbac6cb3..3c11f666 100644
--- a/src/reel_sound_asset.cc
+++ b/src/reel_sound_asset.cc
@@ -93,3 +93,15 @@ ReelSoundAsset::equals(shared_ptr<const ReelSoundAsset> other, EqualityOptions c
return true;
}
+
+
+bool
+ReelSoundAsset::can_be_read() const
+{
+ if (!ReelFileAsset::can_be_read()) {
+ return false;
+ }
+
+ return asset()->can_be_read();
+}
+
diff --git a/src/reel_sound_asset.h b/src/reel_sound_asset.h
index 6537ab5c..ac157bdb 100644
--- a/src/reel_sound_asset.h
+++ b/src/reel_sound_asset.h
@@ -55,6 +55,8 @@ public:
ReelSoundAsset (std::shared_ptr<dcp::SoundAsset> content, int64_t entry_point);
explicit ReelSoundAsset (std::shared_ptr<const cxml::Node>);
+ bool can_be_read() const override;
+
/** @return the SoundAsset that this object refers to */
std::shared_ptr<const SoundAsset> asset () const {
return asset_of_type<const SoundAsset>();
diff --git a/src/reel_stereo_picture_asset.cc b/src/reel_stereo_picture_asset.cc
index 2ee452d9..53abb8d6 100644
--- a/src/reel_stereo_picture_asset.cc
+++ b/src/reel_stereo_picture_asset.cc
@@ -42,10 +42,11 @@
#include <libcxml/cxml.h>
-using std::string;
-using std::pair;
+using std::dynamic_pointer_cast;
using std::make_pair;
+using std::pair;
using std::shared_ptr;
+using std::string;
using namespace dcp;
@@ -82,3 +83,15 @@ ReelStereoPictureAsset::cpl_node_attribute (Standard standard) const
DCP_ASSERT (false);
}
+
+
+bool
+ReelStereoPictureAsset::can_be_read() const
+{
+ if (!ReelFileAsset::can_be_read()) {
+ return false;
+ }
+
+ return asset()->can_be_read();
+}
+
diff --git a/src/reel_stereo_picture_asset.h b/src/reel_stereo_picture_asset.h
index 0dd726a4..9e5b30cf 100644
--- a/src/reel_stereo_picture_asset.h
+++ b/src/reel_stereo_picture_asset.h
@@ -60,6 +60,8 @@ public:
ReelStereoPictureAsset (std::shared_ptr<StereoJ2KPictureAsset> content, int64_t entry_point);
explicit ReelStereoPictureAsset (std::shared_ptr<const cxml::Node>);
+ bool can_be_read() const override;
+
/** @return the StereoJ2KPictureAsset that this object refers to */
std::shared_ptr<const StereoJ2KPictureAsset> stereo_asset () const {
return asset_of_type<const StereoJ2KPictureAsset>();
diff --git a/src/smpte_text_asset.cc b/src/smpte_text_asset.cc
index 63e8c8ab..84624171 100644
--- a/src/smpte_text_asset.cc
+++ b/src/smpte_text_asset.cc
@@ -615,3 +615,24 @@ SMPTETextAsset::schema_namespace() const
DCP_ASSERT(false);
}
+
+
+
+bool
+SMPTETextAsset::can_be_read() const
+{
+ if (!MXF::can_be_read()) {
+ return false;
+ }
+
+ try {
+ texts();
+ } catch (dcp::ReadError&) {
+ return false;
+ } catch (dcp::MiscError&) {
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/src/smpte_text_asset.h b/src/smpte_text_asset.h
index 6a08ffe4..9b7f09a6 100644
--- a/src/smpte_text_asset.h
+++ b/src/smpte_text_asset.h
@@ -82,6 +82,8 @@ public:
*/
explicit SMPTETextAsset(boost::filesystem::path file);
+ bool can_be_read() const override;
+
bool equals (
std::shared_ptr<const Asset>,
EqualityOptions const&,
diff --git a/src/sound_asset.cc b/src/sound_asset.cc
index f671a58a..614f6165 100644
--- a/src/sound_asset.cc
+++ b/src/sound_asset.cc
@@ -294,3 +294,24 @@ SoundAsset::active_channels() const
return _active_channels.get_value_or(_channels);
}
+
+bool
+SoundAsset::can_be_read() const
+{
+ if (!MXF::can_be_read()) {
+ return false;
+ }
+
+ try {
+ auto reader = start_read();
+ reader->set_check_hmac(false);
+ reader->get_frame(0);
+ } catch (dcp::ReadError&) {
+ return false;
+ } catch (dcp::MiscError&) {
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/src/sound_asset.h b/src/sound_asset.h
index e5acb119..64bc0a03 100644
--- a/src/sound_asset.h
+++ b/src/sound_asset.h
@@ -84,6 +84,8 @@ public:
DISABLED
};
+ bool can_be_read() const override;
+
/** @param extra_active_channels list of channels that are active in the asset, other than the basic 5.1
* which are assumed always to be active.
*/
diff --git a/src/stereo_j2k_picture_asset.cc b/src/stereo_j2k_picture_asset.cc
index 6a5e7d79..d403ed41 100644
--- a/src/stereo_j2k_picture_asset.cc
+++ b/src/stereo_j2k_picture_asset.cc
@@ -181,3 +181,25 @@ StereoJ2KPictureAsset::equals(shared_ptr<const Asset> other, EqualityOptions con
return result;
}
+
+
+bool
+StereoJ2KPictureAsset::can_be_read() const
+{
+ if (!MXF::can_be_read()) {
+ return false;
+ }
+
+ try {
+ auto reader = start_read();
+ reader->set_check_hmac(false);
+ reader->get_frame(0)->xyz_image(Eye::LEFT);
+ } catch (dcp::ReadError&) {
+ return false;
+ } catch (dcp::MiscError&) {
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/src/stereo_j2k_picture_asset.h b/src/stereo_j2k_picture_asset.h
index 7ef86ec5..6c870d59 100644
--- a/src/stereo_j2k_picture_asset.h
+++ b/src/stereo_j2k_picture_asset.h
@@ -57,6 +57,8 @@ public:
explicit StereoJ2KPictureAsset (boost::filesystem::path file);
explicit StereoJ2KPictureAsset (Fraction edit_rate, Standard standard);
+ bool can_be_read() const override;
+
/** Start a progressive write to a StereoJ2KPictureAsset */
std::shared_ptr<J2KPictureAssetWriter> start_write(boost::filesystem::path file, Behaviour behaviour) override;
std::shared_ptr<StereoJ2KPictureAssetReader> start_read () const;