--- /dev/null
+/*
+ Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file src/exceptions.h
+ * @brief Exceptions thrown by libdcp.
+ */
+
+namespace libdcp
+{
+
+class FileError : public std::exception
+{
+public:
+ FileError (std::string const & message, std::string const & filename)
+ : _message (message)
+ , _filename (filename)
+ {}
+
+ ~FileError () throw () {}
+
+ char const * what () const throw () {
+ return _message.c_str ();
+ }
+
+ std::string filename () const {
+ return _filename;
+ }
+
+private:
+ std::string _message;
+ std::string _filename;
+};
+
+class MiscError : public std::exception
+{
+public:
+ MiscError (std::string const & message) : _message (message) {}
+ ~MiscError () throw () {}
+
+ char const * what () const throw () {
+ return _message.c_str ();
+ }
+
+private:
+ std::string _message;
+};
+
+}
#include "KM_fileio.h"
#include "picture_asset.h"
#include "util.h"
+#include "exceptions.h"
using namespace std;
using namespace boost;
ASDCP::JP2K::CodestreamParser j2k_parser;
ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte);
if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (get_path(0).c_str(), frame_buffer))) {
- stringstream s;
- s << "could not open " << get_path(0) << " for reading";
- throw runtime_error (s.str());
+ throw FileError ("could not open JPEG2000 file for reading", get_path (0));
}
ASDCP::JP2K::PictureDescriptor picture_desc;
ASDCP::JP2K::MXFWriter mxf_writer;
if (ASDCP_FAILURE (mxf_writer.OpenWrite (_mxf_path.c_str(), writer_info, picture_desc))) {
- throw runtime_error ("could not open MXF for writing");
+ throw FileError ("could not open MXF file for writing", _mxf_path);
}
for (int i = 0; i < _length; ++i) {
string const path = get_path (i);
if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (path.c_str(), frame_buffer))) {
- stringstream s;
- s << "could not open " << path << " for reading";
- throw runtime_error (s.str());
+ throw FileError ("could not open JPEG2000 file for reading", path);
}
/* XXX: passing 0 to WriteFrame ok? */
if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
- throw runtime_error ("error in writing video MXF");
+ throw MiscError ("error in writing video MXF");
}
(*_progress) (0.5 * float (i) / _length);
}
if (ASDCP_FAILURE (mxf_writer.Finalize())) {
- throw runtime_error ("error in finalising video MXF");
+ throw MiscError ("error in finalising video MXF");
}
_digest = make_digest (_mxf_path, _progress);
#include "AS_DCP.h"
#include "sound_asset.h"
#include "util.h"
+#include "exceptions.h"
using namespace std;
using namespace boost;
ASDCP::PCM::WAVParser pcm_parser_channel[_channels];
if (pcm_parser_channel[0].OpenRead (get_path(LEFT).c_str(), asdcp_fps)) {
- throw runtime_error ("could not open WAV file for reading");
+ throw FileError ("could not open WAV file for reading", get_path(LEFT));
}
ASDCP::PCM::AudioDescriptor audio_desc;
string const path = get_path (channels[i]);
if (ASDCP_FAILURE (pcm_parser_channel[i].OpenRead (path.c_str(), asdcp_fps))) {
- throw runtime_error ("could not open WAV file for reading");
+ throw FileError ("could not open WAV file for reading", path);
}
pcm_parser_channel[i].FillAudioDescriptor (audio_desc_channel[i]);
ASDCP::PCM::MXFWriter mxf_writer;
if (ASDCP_FAILURE (mxf_writer.OpenWrite (_mxf_path.c_str(), writer_info, audio_desc))) {
- throw runtime_error ("could not open audio MXF for writing");
+ throw FileError ("could not open audio MXF for writing", _mxf_path);
}
for (int i = 0; i < _length; ++i) {
for (int j = 0; j < _channels; ++j) {
memset (frame_buffer_channel[j].Data(), 0, frame_buffer_channel[j].Capacity());
if (ASDCP_FAILURE (pcm_parser_channel[j].ReadFrame (frame_buffer_channel[j]))) {
- throw runtime_error ("could not read audio frame");
+ throw MiscError ("could not read audio frame");
}
if (frame_buffer_channel[j].Size() != frame_buffer_channel[j].Capacity()) {
- throw runtime_error ("short audio frame");
+ throw MiscError ("short audio frame");
}
}
}
if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
- throw runtime_error ("could not write audio MXF frame");
+ throw MiscError ("could not write audio MXF frame");
}
(*_progress) (0.5 * float (i) / _length);
}
if (ASDCP_FAILURE (mxf_writer.Finalize())) {
- throw runtime_error ("could not finalise audio MXF");
+ throw MiscError ("could not finalise audio MXF");
}
_digest = make_digest (_mxf_path, _progress);
#include "KM_fileio.h"
#include "AS_DCP.h"
#include "util.h"
+#include "exceptions.h"
using namespace std;
using namespace boost;
Kumu::FileReader reader;
if (ASDCP_FAILURE (reader.OpenRead (filename.c_str ()))) {
- throw runtime_error ("could not open file to compute digest");
+ throw FileError ("could not open file to compute digest", filename);
}
SHA_CTX sha;
if (r == Kumu::RESULT_ENDOFFILE) {
break;
} else if (ASDCP_FAILURE (r)) {
- throw runtime_error ("could not read file to compute digest");
+ throw FileError ("could not read file to compute digest", filename);
}
SHA1_Update (&sha, read_buffer.Data(), read);
dcp.h
metadata.h
types.h
+ exceptions.h
"""
bld.install_files('${PREFIX}/include/libdcp', headers)