summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-07-17 20:30:30 +0100
committerCarl Hetherington <cth@carlh.net>2012-07-17 20:30:30 +0100
commit4709b2fe88040f3678560997726f3a209eacc660 (patch)
treedb4c7f923de4bd4e09de6c5237288424f0622a24 /src
parent43cc9d6e1b1e1957288c545cc55f5a0df8492b55 (diff)
Fix up progress reporting, some better exceptions.
Diffstat (limited to 'src')
-rw-r--r--src/asset.cc3
-rw-r--r--src/asset.h9
-rw-r--r--src/dcp.cc6
-rw-r--r--src/dcp.h11
-rw-r--r--src/picture_asset.cc17
-rw-r--r--src/picture_asset.h2
-rw-r--r--src/sound_asset.cc8
-rw-r--r--src/sound_asset.h2
-rw-r--r--src/util.cc12
-rw-r--r--src/util.h3
10 files changed, 49 insertions, 24 deletions
diff --git a/src/asset.cc b/src/asset.cc
index e2624712..4a44e11f 100644
--- a/src/asset.cc
+++ b/src/asset.cc
@@ -35,8 +35,9 @@ using namespace libdcp;
* @param len Length in frames.
*/
-Asset::Asset (string p, int fps, int len)
+Asset::Asset (string p, sigc::signal1<void, float>* progress, int fps, int len)
: _mxf_path (p)
+ , _progress (progress)
, _fps (fps)
, _length (len)
, _uuid (make_uuid ())
diff --git a/src/asset.h b/src/asset.h
index fb701570..2d33e069 100644
--- a/src/asset.h
+++ b/src/asset.h
@@ -34,22 +34,19 @@ namespace libdcp
class Asset
{
public:
- Asset (std::string, int, int);
+ Asset (std::string, sigc::signal1<void, float>*, int, int);
virtual void write_to_cpl (std::ostream &) const = 0;
void write_to_pkl (std::ostream &) const;
void write_to_assetmap (std::ostream &) const;
- /** Emitted with a parameter between 0 and 1 to indicate progress in constructing
- * this asset.
- */
- sigc::signal1<void, float> Progress;
-
protected:
void fill_writer_info (ASDCP::WriterInfo *) const;
/** Path to our MXF file */
std::string _mxf_path;
+ /** Signal to emit to report progress */
+ sigc::signal1<void, float>* _progress;
/** Frames per second */
int _fps;
/** Length in frames */
diff --git a/src/dcp.cc b/src/dcp.cc
index b691d146..9a7c367b 100644
--- a/src/dcp.cc
+++ b/src/dcp.cc
@@ -58,7 +58,7 @@ DCP::add_sound_asset (list<string> const & files)
filesystem::path p;
p /= _directory;
p /= "audio.mxf";
- _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (files, p.string(), _fps, _length)));
+ _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (files, p.string(), &Progress, _fps, _length)));
}
/** Add a picture asset.
@@ -70,7 +70,7 @@ DCP::add_picture_asset (list<string> const & files, int w, int h)
filesystem::path p;
p /= _directory;
p /= "video.mxf";
- _assets.push_back (shared_ptr<PictureAsset> (new PictureAsset (files, p.string(), _fps, _length, w, h)));
+ _assets.push_back (shared_ptr<PictureAsset> (new PictureAsset (files, p.string(), &Progress, _fps, _length, w, h)));
}
/** Write the required XML files to the directory that was
@@ -82,7 +82,7 @@ DCP::write_xml () const
string cpl_uuid = make_uuid ();
string cpl_path = write_cpl (cpl_uuid);
int cpl_length = filesystem::file_size (cpl_path);
- string cpl_digest = make_digest (cpl_path);
+ string cpl_digest = make_digest (cpl_path, 0);
string pkl_uuid = make_uuid ();
string pkl_path = write_pkl (pkl_uuid, cpl_uuid, cpl_digest, cpl_length);
diff --git a/src/dcp.h b/src/dcp.h
index 6896267c..6170896b 100644
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -17,9 +17,13 @@
*/
+#ifndef LIBDCP_DCP_H
+#define LIBDCP_DCP_H
+
#include <string>
#include <list>
#include <boost/shared_ptr.hpp>
+#include <sigc++/sigc++.h>
namespace libdcp
{
@@ -51,6 +55,11 @@ public:
void write_xml () const;
+ /** Emitted with a parameter between 0 and 1 to indicate progress
+ * for long jobs.
+ */
+ sigc::signal1<void, float> Progress;
+
private:
std::string write_cpl (std::string) const;
@@ -75,3 +84,5 @@ private:
};
}
+
+#endif
diff --git a/src/picture_asset.cc b/src/picture_asset.cc
index 1f131234..c989539b 100644
--- a/src/picture_asset.cc
+++ b/src/picture_asset.cc
@@ -20,6 +20,7 @@
#include <list>
#include <stdexcept>
#include <iostream>
+#include <sstream>
#include <boost/filesystem.hpp>
#include "AS_DCP.h"
#include "KM_fileio.h"
@@ -40,15 +41,17 @@ using namespace libdcp;
* @param h Height of images in pixels.
*/
-PictureAsset::PictureAsset (list<string> const & files, string p, int fps, int len, int w, int h)
- : Asset (p, fps, len)
+PictureAsset::PictureAsset (list<string> const & files, string p, sigc::signal1<void, float>* progress, int fps, int len, int w, int h)
+ : Asset (p, progress, fps, len)
, _width (w)
, _height (h)
{
ASDCP::JP2K::CodestreamParser j2k_parser;
ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte);
if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (files.front().c_str(), frame_buffer))) {
- throw runtime_error ("could not open J2K file for reading");
+ stringstream s;
+ s << "could not open " << files.front() << " for reading";
+ throw runtime_error (s.str());
}
ASDCP::JP2K::PictureDescriptor picture_desc;
@@ -66,7 +69,9 @@ PictureAsset::PictureAsset (list<string> const & files, string p, int fps, int l
int j = 0;
for (list<string>::const_iterator i = files.begin(); i != files.end(); ++i) {
if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (i->c_str(), frame_buffer))) {
- throw runtime_error ("could not open J2K file for reading");
+ stringstream s;
+ s << "could not open " << *i << " for reading";
+ throw runtime_error (s.str());
}
/* XXX: passing 0 to WriteFrame ok? */
@@ -75,14 +80,14 @@ PictureAsset::PictureAsset (list<string> const & files, string p, int fps, int l
}
++j;
- Progress (float (j) / files.size ());
+ (*_progress) (0.5 * float (j) / files.size ());
}
if (ASDCP_FAILURE (mxf_writer.Finalize())) {
throw runtime_error ("error in finalising video MXF");
}
- _digest = make_digest (_mxf_path);
+ _digest = make_digest (_mxf_path, _progress);
}
/** Write details of this asset to a CPL stream.
diff --git a/src/picture_asset.h b/src/picture_asset.h
index 8883e538..3027a789 100644
--- a/src/picture_asset.h
+++ b/src/picture_asset.h
@@ -26,7 +26,7 @@ namespace libdcp
class PictureAsset : public Asset
{
public:
- PictureAsset (std::list<std::string> const &, std::string, int, int, int, int);
+ PictureAsset (std::list<std::string> const &, std::string, sigc::signal1<void, float>*, int, int, int, int);
void write_to_cpl (std::ostream &) const;
diff --git a/src/sound_asset.cc b/src/sound_asset.cc
index 9dba4ed6..50bf463c 100644
--- a/src/sound_asset.cc
+++ b/src/sound_asset.cc
@@ -36,8 +36,8 @@ using namespace libdcp;
* @param len Length in frames.
*/
-SoundAsset::SoundAsset (list<string> const & files, string p, int fps, int len)
- : Asset (p, fps, len)
+SoundAsset::SoundAsset (list<string> const & files, string p, sigc::signal1<void, float>* progress, int fps, int len)
+ : Asset (p, progress, fps, len)
{
ASDCP::Rational asdcp_fps (_fps, 1);
@@ -114,14 +114,14 @@ SoundAsset::SoundAsset (list<string> const & files, string p, int fps, int len)
throw runtime_error ("could not write audio MXF frame");
}
- Progress (float (i) / _length);
+ (*_progress) (0.5 * float (i) / _length);
}
if (ASDCP_FAILURE (mxf_writer.Finalize())) {
throw runtime_error ("could not finalise audio MXF");
}
- _digest = make_digest (_mxf_path);
+ _digest = make_digest (_mxf_path, _progress);
}
/** Write details of this asset to a CPL stream.
diff --git a/src/sound_asset.h b/src/sound_asset.h
index 0327adf4..aa1362f6 100644
--- a/src/sound_asset.h
+++ b/src/sound_asset.h
@@ -26,7 +26,7 @@ namespace libdcp
class SoundAsset : public Asset
{
public:
- SoundAsset (std::list<std::string> const &, std::string, int, int);
+ SoundAsset (std::list<std::string> const &, std::string, sigc::signal1<void, float>*, int, int);
void write_to_cpl (std::ostream &) const;
};
diff --git a/src/util.cc b/src/util.cc
index c9f50289..0af9c871 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -21,6 +21,7 @@
#include <sstream>
#include <iostream>
#include <iomanip>
+#include <boost/filesystem.hpp>
#include <openssl/sha.h>
#include "KM_util.h"
#include "KM_fileio.h"
@@ -28,6 +29,7 @@
#include "util.h"
using namespace std;
+using namespace boost;
/** Create a UUID.
* @return UUID.
@@ -47,8 +49,10 @@ libdcp::make_uuid ()
* @return Digest.
*/
string
-libdcp::make_digest (string filename)
+libdcp::make_digest (string filename, sigc::signal1<void, float>* progress)
{
+ int const file_size = filesystem::file_size (filename);
+
Kumu::FileReader reader;
if (ASDCP_FAILURE (reader.OpenRead (filename.c_str ()))) {
throw runtime_error ("could not open file to compute digest");
@@ -58,6 +62,7 @@ libdcp::make_digest (string filename)
SHA1_Init (&sha);
Kumu::ByteString read_buffer (65536);
+ int done = 0;
while (1) {
ui32_t read = 0;
Kumu::Result_t r = reader.Read (read_buffer.Data(), read_buffer.Capacity(), &read);
@@ -69,6 +74,11 @@ libdcp::make_digest (string filename)
}
SHA1_Update (&sha, read_buffer.Data(), read);
+ done += read;
+
+ if (progress) {
+ (*progress) (0.5 + (0.5 * done / file_size));
+ }
}
byte_t byte_buffer[20];
diff --git a/src/util.h b/src/util.h
index 0a5292c0..9ed674f7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -18,10 +18,11 @@
*/
#include <string>
+#include <sigc++/sigc++.h>
namespace libdcp {
extern std::string make_uuid ();
-extern std::string make_digest (std::string);
+extern std::string make_digest (std::string, sigc::signal1<void, float> *);
}