summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-07-14 23:51:21 +0200
committerCarl Hetherington <cth@carlh.net>2022-07-14 23:51:21 +0200
commitbdf7390c9ec8b24d6f007c4a53c191bb60c0fc75 (patch)
tree55651e4561e69d61a251dc9ff6701b9e72093ade
parent860296bc2a6ffdb8dcf407a2a4ff985ccc30b87d (diff)
Close assets on destruction even if finalize() is not called.v1.8.23
-rw-r--r--src/mono_picture_asset_writer.cc12
-rw-r--r--src/mono_picture_asset_writer.h8
-rw-r--r--src/sound_asset_writer.cc12
-rw-r--r--src/sound_asset_writer.h2
-rw-r--r--src/stereo_picture_asset_writer.cc12
-rw-r--r--src/stereo_picture_asset_writer.h8
6 files changed, 48 insertions, 6 deletions
diff --git a/src/mono_picture_asset_writer.cc b/src/mono_picture_asset_writer.cc
index 1abdcccc..b2b829fa 100644
--- a/src/mono_picture_asset_writer.cc
+++ b/src/mono_picture_asset_writer.cc
@@ -74,6 +74,17 @@ MonoPictureAssetWriter::MonoPictureAssetWriter (PictureAsset* asset, boost::file
}
+MonoPictureAssetWriter::~MonoPictureAssetWriter()
+{
+ try {
+ /* Last-resort finalization to close the file, at least */
+ if (_started) {
+ _state->mxf_writer.Finalize();
+ }
+ } catch (...) {}
+}
+
+
void
MonoPictureAssetWriter::start (uint8_t const * data, int size)
{
@@ -131,6 +142,7 @@ MonoPictureAssetWriter::finalize ()
if (ASDCP_FAILURE(r)) {
boost::throw_exception (MXFFileError("error in finalizing video MXF", _file.string(), r));
}
+ _started = false;
}
_picture_asset->_intrinsic_duration = _frames_written;
diff --git a/src/mono_picture_asset_writer.h b/src/mono_picture_asset_writer.h
index 724e4ece..551d8c80 100644
--- a/src/mono_picture_asset_writer.h
+++ b/src/mono_picture_asset_writer.h
@@ -57,13 +57,15 @@ namespace dcp {
* Objects of this class can only be created with MonoPictureAsset::start_write().
*
* Frames can be written to the MonoPictureAsset by calling write() with a JPEG2000 image
- * (a verbatim .j2c file). finalize() must be called after the last frame has been written.
- * The action of finalize() can't be done in MonoPictureAssetWriter's destructor as it may
- * throw an exception.
+ * (a verbatim .j2c file). finalize() should be called after the last frame has been written,
+ * but if it is not, it will be called by the destructor (though in that case any error
+ * during finalization will be ignored).
*/
class MonoPictureAssetWriter : public PictureAssetWriter
{
public:
+ ~MonoPictureAssetWriter();
+
FrameInfo write (uint8_t const *, int) override;
void fake_write (int size) override;
bool finalize () override;
diff --git a/src/sound_asset_writer.cc b/src/sound_asset_writer.cc
index 2842a1d5..40acf924 100644
--- a/src/sound_asset_writer.cc
+++ b/src/sound_asset_writer.cc
@@ -111,6 +111,17 @@ SoundAssetWriter::SoundAssetWriter (SoundAsset* asset, boost::filesystem::path f
}
+SoundAssetWriter::~SoundAssetWriter()
+{
+ try {
+ /* Last-resort finalization to close the file, at least */
+ if (_started) {
+ _state->mxf_writer.Finalize();
+ }
+ } catch (...) {}
+}
+
+
void
SoundAssetWriter::start ()
{
@@ -265,6 +276,7 @@ SoundAssetWriter::finalize ()
if (ASDCP_FAILURE(r)) {
boost::throw_exception (MiscError(String::compose ("could not finalise audio MXF (%1)", static_cast<int>(r))));
}
+ _started = false;
}
_asset->_intrinsic_duration = _frames_written;
diff --git a/src/sound_asset_writer.h b/src/sound_asset_writer.h
index fde56d95..031af5c9 100644
--- a/src/sound_asset_writer.h
+++ b/src/sound_asset_writer.h
@@ -67,6 +67,8 @@ class SoundAsset;
class SoundAssetWriter : public AssetWriter
{
public:
+ ~SoundAssetWriter();
+
/** @param data Pointer an array of float pointers, one for each channel.
* @param frames Number of frames i.e. number of floats that are given for each channel.
*/
diff --git a/src/stereo_picture_asset_writer.cc b/src/stereo_picture_asset_writer.cc
index e02e8360..f4ec7df0 100644
--- a/src/stereo_picture_asset_writer.cc
+++ b/src/stereo_picture_asset_writer.cc
@@ -68,6 +68,17 @@ StereoPictureAssetWriter::StereoPictureAssetWriter (PictureAsset* mxf, boost::fi
}
+StereoPictureAssetWriter::~StereoPictureAssetWriter()
+{
+ try {
+ /* Last-resort finalization to close the file, at least */
+ if (_started) {
+ _state->mxf_writer.Finalize();
+ }
+ } catch (...) {}
+}
+
+
void
StereoPictureAssetWriter::start (uint8_t const * data, int size)
{
@@ -140,6 +151,7 @@ StereoPictureAssetWriter::finalize ()
if (ASDCP_FAILURE(r)) {
boost::throw_exception (MXFFileError("error in finalizing video MXF", _file.string(), r));
}
+ _started = false;
}
_picture_asset->_intrinsic_duration = _frames_written;
diff --git a/src/stereo_picture_asset_writer.h b/src/stereo_picture_asset_writer.h
index 0a361e41..287e7ecd 100644
--- a/src/stereo_picture_asset_writer.h
+++ b/src/stereo_picture_asset_writer.h
@@ -53,13 +53,15 @@ namespace dcp {
* Objects of this class can only be created with StereoPictureAsset::start_write().
*
* Frames can be written to the StereoPictureAsset by calling write() with a JPEG2000 image
- * (a verbatim .j2c file). finalize() must be called after the last frame has been written.
- * The action of finalize() can't be done in StereoPictureAssetWriter's destructor as it may
- * throw an exception.
+ * (a verbatim .j2c file). finalize() should be called after the last frame has been written,
+ * but if it is not, it will be called by the destructor (though in that case any error
+ * during finalization will be ignored).
*/
class StereoPictureAssetWriter : public PictureAssetWriter
{
public:
+ ~StereoPictureAssetWriter();
+
/** Write a frame for one eye. Frames must be written left, then right, then left etc.
* @param data JPEG2000 data.
* @param size Size of data.