From 314060f975dc9806f49ec8bbb1c11041a2ac111f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 13 Apr 2020 22:55:53 +0200 Subject: Add a special exception for the case when opj_start_compress fails. --- src/exceptions.cc | 10 +++++++++- src/exceptions.h | 14 ++++++++++++++ src/j2k.cc | 4 ++-- 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/exceptions.cc b/src/exceptions.cc index a49c7004..7f389f31 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2019 Carl Hetherington + Copyright (C) 2014-2020 Carl Hetherington This file is part of libdcp. @@ -40,6 +40,7 @@ using std::string; using std::runtime_error; +using boost::optional; using namespace dcp; FileError::FileError (string message, boost::filesystem::path filename, int number) @@ -123,3 +124,10 @@ BadKDMDateError::BadKDMDateError (bool starts_too_early) { } + + +StartCompressionError::StartCompressionError (optional code) + : runtime_error (String::compose("Could not start JPEG2000 encoding%1", code ? String::compose(" (%1", *code) : "")) + , _code (code) +{} + diff --git a/src/exceptions.h b/src/exceptions.h index ccf7a081..770bd916 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -211,6 +211,20 @@ private: bool _starts_too_early; }; + +class StartCompressionError : public std::runtime_error +{ +public: + explicit StartCompressionError (boost::optional code = boost::optional()); + + boost::optional code () const { + return _code; + } + +private: + boost::optional _code; +}; + } #endif diff --git a/src/j2k.cc b/src/j2k.cc index f1e4c3f5..a81da68c 100644 --- a/src/j2k.cc +++ b/src/j2k.cc @@ -310,9 +310,9 @@ dcp::compress_j2k (shared_ptr xyz, int bandwidth, int frame if (!opj_start_compress (encoder, xyz->opj_image(), stream)) { if ((errno & 0x61500) == 0x61500) { /* We've had one of the magic error codes from our patched openjpeg */ - throw MiscError (String::compose ("could not start JPEG2000 encoding (%1)", errno & 0xff)); + boost::throw_exception (StartCompressionError (errno & 0xff)); } else { - throw MiscError ("could not start JPEG2000 encoding"); + boost::throw_exception (StartCompressionError ()); } } -- cgit v1.2.3