summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-08-09 23:27:15 +0100
committerCarl Hetherington <cth@carlh.net>2012-08-09 23:27:15 +0100
commitf6ee90107839e0d750d8678b67c9d6d1d596d739 (patch)
tree27c500a6e1c0c56e3fa54dff2c2a401c6f06e114 /src
parentc2c7b454d8ca179880942e3341dd8b17c084f5a3 (diff)
Add picture frame extraction.
Diffstat (limited to 'src')
-rw-r--r--src/asset.cc10
-rw-r--r--src/asset.h3
-rw-r--r--src/dcp.cc13
-rw-r--r--src/dcp.h3
-rw-r--r--src/picture_asset.cc7
-rw-r--r--src/picture_asset.h4
-rw-r--r--src/picture_frame.cc58
-rw-r--r--src/picture_frame.h38
-rw-r--r--src/wscript3
9 files changed, 136 insertions, 3 deletions
diff --git a/src/asset.cc b/src/asset.cc
index 78686a17..d8cf25da 100644
--- a/src/asset.cc
+++ b/src/asset.cc
@@ -159,6 +159,10 @@ Asset::digest () const
return _digest;
}
-
-
-
+int
+Asset::length () const
+{
+ return _length;
+}
+
+
diff --git a/src/asset.h b/src/asset.h
index 6c0a9803..b7b2065b 100644
--- a/src/asset.h
+++ b/src/asset.h
@@ -25,6 +25,7 @@
#define LIBDCP_ASSET_H
#include <string>
+#include <boost/filesystem.hpp>
#include <sigc++/sigc++.h>
#include "types.h"
@@ -68,6 +69,8 @@ public:
virtual std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const;
+ int length () const;
+
protected:
friend class PictureAsset;
friend class SoundAsset;
diff --git a/src/dcp.cc b/src/dcp.cc
index 53d6b55d..b6014941 100644
--- a/src/dcp.cc
+++ b/src/dcp.cc
@@ -369,3 +369,16 @@ DCP::equals (DCP const & other, EqualityOptions opt) const
return notes;
}
+
+shared_ptr<const PictureAsset>
+DCP::picture_asset () const
+{
+ for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
+ shared_ptr<PictureAsset> p = dynamic_pointer_cast<PictureAsset> (*i);
+ if (p) {
+ return p;
+ }
+ }
+
+ return shared_ptr<const PictureAsset> ();
+}
diff --git a/src/dcp.h b/src/dcp.h
index 5a429a17..924a9f4f 100644
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -39,6 +39,7 @@ namespace libdcp
{
class Asset;
+class PictureAsset;
/** @class DCP dcp.h libdcp/dcp.h
* @brief A class to create or read a DCP.
@@ -106,6 +107,8 @@ public:
return _length;
}
+ boost::shared_ptr<const PictureAsset> picture_asset () const;
+
std::list<std::string> equals (DCP const & other, EqualityOptions options) const;
/** Emitted with a parameter between 0 and 1 to indicate progress
diff --git a/src/picture_asset.cc b/src/picture_asset.cc
index c59664d9..d7036a19 100644
--- a/src/picture_asset.cc
+++ b/src/picture_asset.cc
@@ -34,6 +34,7 @@
#include "picture_asset.h"
#include "util.h"
#include "exceptions.h"
+#include "picture_frame.h"
using namespace std;
using namespace boost;
@@ -303,3 +304,9 @@ PictureAsset::decompress_j2k (uint8_t* data, int64_t size) const
opj_cio_close (cio);
return image;
}
+
+shared_ptr<const PictureFrame>
+PictureAsset::get_frame (int n) const
+{
+ return shared_ptr<const PictureFrame> (new PictureFrame (mxf_path().string(), n));
+}
diff --git a/src/picture_asset.h b/src/picture_asset.h
index 41b09b58..4e1801f9 100644
--- a/src/picture_asset.h
+++ b/src/picture_asset.h
@@ -27,6 +27,8 @@
namespace libdcp
{
+class PictureFrame;
+
/** @brief An asset made up of JPEG2000 files */
class PictureAsset : public Asset
{
@@ -83,6 +85,8 @@ public:
void write_to_cpl (std::ostream& s) const;
std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const;
+
+ boost::shared_ptr<const PictureFrame> get_frame (int n) const;
private:
std::string path_from_list (int f, std::vector<std::string> const & files) const;
diff --git a/src/picture_frame.cc b/src/picture_frame.cc
new file mode 100644
index 00000000..d2ef698f
--- /dev/null
+++ b/src/picture_frame.cc
@@ -0,0 +1,58 @@
+/*
+ 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.
+
+*/
+
+#include "AS_DCP.h"
+#include "KM_fileio.h"
+#include "picture_frame.h"
+#include "exceptions.h"
+
+using namespace std;
+using namespace libdcp;
+
+PictureFrame::PictureFrame (string mxf_path, int n)
+{
+ ASDCP::JP2K::MXFReader reader;
+ if (ASDCP_FAILURE (reader.OpenRead (mxf_path.c_str()))) {
+ throw FileError ("could not open MXF file for reading", mxf_path);
+ }
+
+ /* XXX: unfortunate guesswork on this buffer size */
+ _buffer = new ASDCP::JP2K::FrameBuffer (4 * Kumu::Megabyte);
+
+ if (ASDCP_FAILURE (reader.ReadFrame (n, *_buffer))) {
+ throw DCPReadError ("could not read video frame");
+ }
+}
+
+PictureFrame::~PictureFrame ()
+{
+ delete _buffer;
+}
+
+uint8_t const *
+PictureFrame::data () const
+{
+ return _buffer->RoData();
+}
+
+int
+PictureFrame::size () const
+{
+ return _buffer->Size ();
+}
diff --git a/src/picture_frame.h b/src/picture_frame.h
new file mode 100644
index 00000000..4d359335
--- /dev/null
+++ b/src/picture_frame.h
@@ -0,0 +1,38 @@
+/*
+ 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.
+
+*/
+
+#include <string>
+#include <stdint.h>
+
+namespace libdcp {
+
+class PictureFrame
+{
+public:
+ PictureFrame (std::string mxf_path, int n);
+ ~PictureFrame ();
+
+ uint8_t const * data () const;
+ int size () const;
+
+private:
+ ASDCP::JP2K::FrameBuffer* _buffer;
+};
+
+}
diff --git a/src/wscript b/src/wscript
index 8caae703..2956029c 100644
--- a/src/wscript
+++ b/src/wscript
@@ -12,6 +12,7 @@ def build(bld):
dcp.cc
sound_asset.cc
picture_asset.cc
+ picture_frame.cc
pkl.cc
util.cc
metadata.cc
@@ -28,6 +29,8 @@ def build(bld):
exceptions.h
test_mode.h
version.h
+ picture_asset.h
+ asset.h
"""
bld.install_files('${PREFIX}/include/libdcp', headers)