summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-04-13 22:55:53 +0200
committerCarl Hetherington <cth@carlh.net>2020-04-14 00:39:30 +0200
commit314060f975dc9806f49ec8bbb1c11041a2ac111f (patch)
tree0cf18abccf70e293165cc6251b041edab48fdf50 /src
parenta840258cea5829b5d0935c588c98bcc0f204afd8 (diff)
Add a special exception for the case when opj_start_compress fails.
Diffstat (limited to 'src')
-rw-r--r--src/exceptions.cc10
-rw-r--r--src/exceptions.h14
-rw-r--r--src/j2k.cc4
3 files changed, 25 insertions, 3 deletions
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 <cth@carlh.net>
+ Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
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<int> 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<int> code = boost::optional<int>());
+
+ boost::optional<int> code () const {
+ return _code;
+ }
+
+private:
+ boost::optional<int> _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<const OpenJPEGImage> 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 ());
}
}