diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-09-10 20:44:52 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-09-13 20:34:07 +0200 |
| commit | 2795ab2e05fcd27a56ddb08ecbbc6af5c3bf983a (patch) | |
| tree | dc66e7590728ace6fd2a7b0f90462f6da712e468 | |
| parent | 97570ebdf7c0dc12a8218a143e2803ec7a792526 (diff) | |
Pass disk full / too many open files errors up to DoM.v1.10.26
| -rw-r--r-- | cscript | 2 | ||||
| -rw-r--r-- | src/exceptions.cc | 15 | ||||
| -rw-r--r-- | src/exceptions.h | 21 | ||||
| -rw-r--r-- | src/mono_j2k_picture_asset_writer.cc | 6 | ||||
| -rw-r--r-- | src/mono_mpeg2_picture_asset_writer.cc | 6 | ||||
| -rw-r--r-- | src/smpte_text_asset.cc | 6 | ||||
| -rw-r--r-- | src/sound_asset_writer.cc | 7 | ||||
| -rw-r--r-- | src/stereo_j2k_picture_asset_writer.cc | 6 | ||||
| -rw-r--r-- | src/util.cc | 23 | ||||
| -rw-r--r-- | src/util.h | 11 |
10 files changed, 87 insertions, 16 deletions
@@ -45,7 +45,7 @@ def dependencies(target, options): deps = [ ('libcxml', 'v0.17.13', { 'c++17': build_with_cpp17(target) }), ('openjpeg', 'ad8edaacd54a862940d0a77c41ecda5858b54d6e'), - ('asdcplib', 'v1.0.7') + ('asdcplib', 'v1.0.8') ] if target.platform == 'linux': diff --git a/src/exceptions.cc b/src/exceptions.cc index 3f354c57..fce1b583 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -218,3 +218,18 @@ LoadVariableZError::LoadVariableZError(string variable_z) { } + + +DiskFullError::DiskFullError(boost::filesystem::path filename) + : runtime_error(fmt::format("Disk full when writing to {}", filename.string())) + , _filename(filename) +{ + +} + + +TooManyOpenFilesError::TooManyOpenFilesError() + : runtime_error("Too many open files") +{ + +} diff --git a/src/exceptions.h b/src/exceptions.h index ee4ef142..49f5a21e 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -365,6 +365,27 @@ public: }; +class DiskFullError : public std::runtime_error +{ +public: + DiskFullError(boost::filesystem::path filename); + + boost::filesystem::path filename() const { + return _filename; + } + +private: + boost::filesystem::path _filename; +}; + + +class TooManyOpenFilesError : public std::runtime_error +{ +public: + TooManyOpenFilesError(); +}; + + } diff --git a/src/mono_j2k_picture_asset_writer.cc b/src/mono_j2k_picture_asset_writer.cc index 1188701e..644cfd3a 100644 --- a/src/mono_j2k_picture_asset_writer.cc +++ b/src/mono_j2k_picture_asset_writer.cc @@ -113,7 +113,7 @@ MonoJ2KPictureAssetWriter::write (uint8_t const * data, int size) string hash; auto const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _crypto_context->context(), _crypto_context->hmac(), &hash); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MXFFileError ("error in writing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in writing video MXF", _file.string(), r)); } ++_frames_written; @@ -129,7 +129,7 @@ MonoJ2KPictureAssetWriter::fake_write(J2KFrameInfo const& info) auto r = _state->mxf_writer.FakeWriteFrame(info.size); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MXFFileError("error in writing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in writing video MXF", _file.string(), r)); } ++_frames_written; @@ -142,7 +142,7 @@ MonoJ2KPictureAssetWriter::finalize () if (_started) { auto r = _state->mxf_writer.Finalize(); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MXFFileError("error in finalizing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in finalizing video MXF", _file.string(), r)); } } diff --git a/src/mono_mpeg2_picture_asset_writer.cc b/src/mono_mpeg2_picture_asset_writer.cc index f8101c54..a8e05ce9 100644 --- a/src/mono_mpeg2_picture_asset_writer.cc +++ b/src/mono_mpeg2_picture_asset_writer.cc @@ -95,7 +95,7 @@ MonoMPEG2PictureAssetWriter::write(uint8_t const * data, int size) string hash; auto const r = _state->mxf_writer.WriteFrame(buffer, _crypto_context->context(), _crypto_context->hmac(), &hash); if (ASDCP_FAILURE(r)) { - boost::throw_exception(MXFFileError("error in writing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in writing video MXF", _file.string(), r)); } ++_frames_written; @@ -121,7 +121,7 @@ MonoMPEG2PictureAssetWriter::fake_write(MPEG2FrameInfo const& info) auto r = _state->mxf_writer.FakeWriteFrame(info.size, info.type, info.gop_start, info.closed_gop, info.temporal_offset); if (ASDCP_FAILURE(r)) { - boost::throw_exception(MXFFileError("error in writing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in writing video MXF", _file.string(), r)); } ++_frames_written; @@ -134,7 +134,7 @@ MonoMPEG2PictureAssetWriter::finalize() if (_started) { auto r = _state->mxf_writer.Finalize(); if (ASDCP_FAILURE(r)) { - boost::throw_exception(MXFFileError("error in finalizing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in finalizing video MXF", _file.string(), r)); } } diff --git a/src/smpte_text_asset.cc b/src/smpte_text_asset.cc index 1e87474a..02ea9a16 100644 --- a/src/smpte_text_asset.cc +++ b/src/smpte_text_asset.cc @@ -466,7 +466,7 @@ SMPTETextAsset::write(boost::filesystem::path p) const r = writer.WriteTimedTextResource (*_raw_xml, enc.context(), enc.hmac()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not write XML to timed text resource", p.string(), r)); + throw_from_asdcplib(r, p, MXFFileError("could not write XML to timed text resource", p.string(), r)); } /* Font payload */ @@ -483,7 +483,7 @@ SMPTETextAsset::write(boost::filesystem::path p) const buffer.Size (j->data.size()); r = writer.WriteAncillaryResource (buffer, enc.context(), enc.hmac()); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MXFFileError ("could not write font to timed text resource", p.string(), r)); + throw_from_asdcplib(r, p, MXFFileError("could not write font to timed text resource", p.string(), r)); } } } @@ -497,7 +497,7 @@ SMPTETextAsset::write(boost::filesystem::path p) const buffer.Size (si->png_image().size()); r = writer.WriteAncillaryResource (buffer, enc.context(), enc.hmac()); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MXFFileError ("could not write PNG data to timed text resource", p.string(), r)); + throw_from_asdcplib(r, p, MXFFileError("could not write PNG data to timed text resource", p.string(), r)); } } } diff --git a/src/sound_asset_writer.cc b/src/sound_asset_writer.cc index 0ebdaa04..0c04e771 100644 --- a/src/sound_asset_writer.cc +++ b/src/sound_asset_writer.cc @@ -51,6 +51,7 @@ LIBDCP_DISABLE_WARNINGS #include <asdcp/AS_DCP.h> #include <asdcp/Metadata.h> LIBDCP_ENABLE_WARNINGS +#include <fmt/format.h> #include <iostream> @@ -150,7 +151,7 @@ SoundAssetWriter::start () { auto r = _state->mxf_writer.OpenWrite(dcp::filesystem::fix_long_path(_file).string().c_str(), _state->writer_info, _state->desc); if (ASDCP_FAILURE(r)) { - boost::throw_exception (FileError("could not open audio MXF for writing", _file.string(), r)); + throw_from_asdcplib(r, _file, FileError("could not open audio MXF for writing", _file.string(), r)); } if (_asset->standard() == Standard::SMPTE && _include_mca_subdescriptors) { @@ -262,7 +263,7 @@ SoundAssetWriter::write_current_frame () { auto const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _crypto_context->context(), _crypto_context->hmac()); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MiscError(String::compose("could not write audio MXF frame (%1)", static_cast<int>(r)))); + throw_from_asdcplib(r, _file, MiscError(fmt::format("could not write audio MXF frame ({})", static_cast<int>(r)))); } ++_frames_written; @@ -283,7 +284,7 @@ SoundAssetWriter::finalize () if (_started) { auto const r = _state->mxf_writer.Finalize(); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MiscError(String::compose ("could not finalise audio MXF (%1)", static_cast<int>(r)))); + throw_from_asdcplib(r, _file, MiscError(fmt::format("could not finalise audio MXF ({})", static_cast<int>(r)))); } } diff --git a/src/stereo_j2k_picture_asset_writer.cc b/src/stereo_j2k_picture_asset_writer.cc index e59de02f..02ccdca1 100644 --- a/src/stereo_j2k_picture_asset_writer.cc +++ b/src/stereo_j2k_picture_asset_writer.cc @@ -114,7 +114,7 @@ StereoJ2KPictureAssetWriter::write (uint8_t const * data, int size) ); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("error in writing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in writing video MXF", _file.string(), r)); } _next_eye = _next_eye == Eye::LEFT ? Eye::RIGHT : Eye::LEFT; @@ -135,7 +135,7 @@ StereoJ2KPictureAssetWriter::fake_write(J2KFrameInfo const& info) auto r = _state->mxf_writer.FakeWriteFrame(info.size, _next_eye == Eye::LEFT ? ASDCP::JP2K::SP_LEFT : ASDCP::JP2K::SP_RIGHT); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MXFFileError("error in writing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in writing video MXF", _file.string(), r)); } _next_eye = _next_eye == Eye::LEFT ? Eye::RIGHT : Eye::LEFT; @@ -151,7 +151,7 @@ StereoJ2KPictureAssetWriter::finalize () if (_started) { auto r = _state->mxf_writer.Finalize(); if (ASDCP_FAILURE(r)) { - boost::throw_exception (MXFFileError("error in finalizing video MXF", _file.string(), r)); + throw_from_asdcplib(r, _file, MXFFileError("error in finalizing video MXF", _file.string(), r)); } } diff --git a/src/util.cc b/src/util.cc index 757553ae..11fcda27 100644 --- a/src/util.cc +++ b/src/util.cc @@ -455,3 +455,26 @@ boost::filesystem::path dcp::resources_directory () } +void +dcp::maybe_throw_from_asdcplib(Kumu::Result_t result, boost::filesystem::path path) +{ + switch (result.OsError()) { + +#ifdef LIBDCP_WINDOWS + case ERROR_DISK_FULL: + case ERROR_HANDLE_DISK_FULL: +#else + case EDQUOT: + case ENOSPC: +#endif + boost::throw_exception(DiskFullError(path)); + +#ifdef LIBDCP_WINDOWS + case ERROR_TOO_MANY_OPEN_FILES: +#else + case EMFILE: +#endif + boost::throw_exception(TooManyOpenFilesError()); + } +} + @@ -42,6 +42,7 @@ #include "array_data.h" +#include "exceptions.h" #include "local_time.h" #include "warnings.h" LIBDCP_DISABLE_WARNINGS @@ -173,6 +174,16 @@ add_to_container(To& container, From source) } +void maybe_throw_from_asdcplib(Kumu::Result_t result, boost::filesystem::path path); + + +template <typename T> +void throw_from_asdcplib(Kumu::Result_t result, boost::filesystem::path path, T const& general) +{ + maybe_throw_from_asdcplib(result, path); + boost::throw_exception(general); +} + } |
