Use a template for AssetReader.
authorCarl Hetherington <cth@carlh.net>
Tue, 27 Sep 2016 10:35:53 +0000 (11:35 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 27 Sep 2016 10:35:53 +0000 (11:35 +0100)
14 files changed:
src/asset_reader.cc [deleted file]
src/asset_reader.h
src/mono_picture_asset.h
src/mono_picture_asset_reader.cc [deleted file]
src/mono_picture_asset_reader.h
src/mono_picture_frame.h
src/sound_asset.h
src/sound_asset_reader.cc [deleted file]
src/sound_asset_reader.h
src/stereo_picture_asset.h
src/stereo_picture_asset_reader.cc [deleted file]
src/stereo_picture_asset_reader.h
src/stereo_picture_frame.h
src/wscript

diff --git a/src/asset_reader.cc b/src/asset_reader.cc
deleted file mode 100644 (file)
index 73c5d01..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
-
-    This file is part of libdcp.
-
-    libdcp 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.
-
-    libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
-
-    In addition, as a special exception, the copyright holders give
-    permission to link the code of portions of this program with the
-    OpenSSL library under certain conditions as described in each
-    individual source file, and distribute linked combinations
-    including the two.
-
-    You must obey the GNU General Public License in all respects
-    for all of the code used other than OpenSSL.  If you modify
-    file(s) with this exception, you may extend this exception to your
-    version of the file(s), but you are not obligated to do so.  If you
-    do not wish to do so, delete this exception statement from your
-    version.  If you delete this exception statement from all source
-    files in the program, then also delete it here.
-*/
-
-#include "asset_reader.h"
-#include "mxf.h"
-#include "exceptions.h"
-#include "decryption_context.h"
-#include <asdcp/AS_DCP.h>
-
-using namespace dcp;
-
-AssetReader::AssetReader (MXF const * mxf)
-       : _decryption_context (new DecryptionContext (mxf->key ()))
-{
-
-}
index 09169a8e0b173ec3ab01c60f8bfc2b0b10150fe2..1cfd9ea2a2aa56dc0097fc4e9929084b585b4be5 100644 (file)
 #ifndef LIBDCP_ASSET_READER_H
 #define LIBDCP_ASSET_READER_H
 
+#include "dcp_assert.h"
+#include "asset.h"
+#include <asdcp/AS_DCP.h>
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
 
 namespace dcp {
 
-class MXF;
 class DecryptionContext;
 
+template <class R, class F>
 class AssetReader : public boost::noncopyable
 {
 public:
-       explicit AssetReader (MXF const * mxf);
-       virtual ~AssetReader () {}
+       explicit AssetReader (Asset const * asset)
+       {
+               _reader = new R ();
+               DCP_ASSERT (asset->file ());
+               Kumu::Result_t const r = _reader->OpenRead (asset->file()->string().c_str());
+               if (ASDCP_FAILURE (r)) {
+                       delete _reader;
+                       boost::throw_exception (FileError ("could not open MXF file for reading", asset->file().get(), r));
+               }
+       }
+
+       ~AssetReader ()
+       {
+               delete _reader;
+       }
+
+       boost::shared_ptr<const F> get_frame (int n) const
+       {
+               return boost::shared_ptr<const F> (new F (_reader, n, _decryption_context));
+       }
 
 protected:
+       R* _reader;
        boost::shared_ptr<DecryptionContext> _decryption_context;
 };
 
index 75ebc3aa562dd61db61b4ab07d2b6877ede5d240..f532db00c92b5f0cc8adbacc5e43ac2ab392cf3a 100644 (file)
 #define LIBDCP_MONO_PICTURE_ASSET_H
 
 #include "picture_asset.h"
+#include "mono_picture_asset_reader.h"
 
 namespace dcp {
 
 class MonoPictureAssetWriter;
-class MonoPictureAssetReader;
 
 /** @class MonoPictureAsset
  *  @brief A 2D (monoscopic) picture asset.
diff --git a/src/mono_picture_asset_reader.cc b/src/mono_picture_asset_reader.cc
deleted file mode 100644 (file)
index f11ec7f..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
-
-    This file is part of libdcp.
-
-    libdcp 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.
-
-    libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
-
-    In addition, as a special exception, the copyright holders give
-    permission to link the code of portions of this program with the
-    OpenSSL library under certain conditions as described in each
-    individual source file, and distribute linked combinations
-    including the two.
-
-    You must obey the GNU General Public License in all respects
-    for all of the code used other than OpenSSL.  If you modify
-    file(s) with this exception, you may extend this exception to your
-    version of the file(s), but you are not obligated to do so.  If you
-    do not wish to do so, delete this exception statement from your
-    version.  If you delete this exception statement from all source
-    files in the program, then also delete it here.
-*/
-
-#include "mono_picture_asset_reader.h"
-#include "mono_picture_asset.h"
-#include "mono_picture_frame.h"
-#include "exceptions.h"
-#include "dcp_assert.h"
-#include <asdcp/AS_DCP.h>
-
-using namespace dcp;
-using boost::shared_ptr;
-
-MonoPictureAssetReader::MonoPictureAssetReader (MonoPictureAsset const * asset)
-       : AssetReader (asset)
-{
-       _reader = new ASDCP::JP2K::MXFReader ();
-       DCP_ASSERT (asset->file ());
-       Kumu::Result_t const r = _reader->OpenRead (asset->file()->string().c_str());
-       if (ASDCP_FAILURE (r)) {
-               delete _reader;
-               boost::throw_exception (FileError ("could not open MXF file for reading", asset->file().get(), r));
-       }
-}
-
-MonoPictureAssetReader::~MonoPictureAssetReader ()
-{
-       delete _reader;
-}
-
-shared_ptr<const MonoPictureFrame>
-MonoPictureAssetReader::get_frame (int n) const
-{
-       return shared_ptr<const MonoPictureFrame> (new MonoPictureFrame (_reader, n, _decryption_context));
-}
index 08f9fde0f4a23759a011d4693f01c0ae2bf818ca..9ec899ccd2947a6810f22d8bdb01416286b4c60a 100644 (file)
 */
 
 #include "asset_reader.h"
-#include <boost/shared_ptr.hpp>
-
-namespace ASDCP {
-       namespace JP2K {
-               class MXFReader;
-       }
-}
 
 namespace dcp {
 
 class MonoPictureFrame;
-class MonoPictureAsset;
-
-class MonoPictureAssetReader : public AssetReader
-{
-public:
-       ~MonoPictureAssetReader ();
-       boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
-
-private:
-       friend class MonoPictureAsset;
-
-       explicit MonoPictureAssetReader (MonoPictureAsset const *);
 
-       ASDCP::JP2K::MXFReader* _reader;
-};
+typedef AssetReader<ASDCP::JP2K::MXFReader, MonoPictureFrame> MonoPictureAssetReader;
 
 }
index cb4afd6f5ffc1e7b339b0cadff2359899b4d3c54..87c5d6ab6c04c80ac565dd47c70ac704d67cb23a 100644 (file)
@@ -36,6 +36,7 @@
  */
 
 #include "types.h"
+#include "mono_picture_asset_reader.h"
 #include <boost/shared_ptr.hpp>
 #include <boost/noncopyable.hpp>
 #include <boost/filesystem.hpp>
@@ -73,7 +74,7 @@ public:
        int j2k_size () const;
 
 private:
-       friend class MonoPictureAssetReader;
+       friend MonoPictureAssetReader;
 
        MonoPictureFrame (ASDCP::JP2K::MXFReader* reader, int n, boost::shared_ptr<DecryptionContext>);
 
index 9278eeeea1a13483e21fa719c95007096e6cebcb..6d09031285edd8fc8e4227448eca521849423db7 100644 (file)
 #include "types.h"
 #include "metadata.h"
 #include "sound_frame.h"
+#include "sound_asset_reader.h"
 
 namespace dcp
 {
 
 class SoundAssetWriter;
-class SoundAssetReader;
 
 /** @class SoundAsset
  *  @brief Representation of a sound asset
diff --git a/src/sound_asset_reader.cc b/src/sound_asset_reader.cc
deleted file mode 100644 (file)
index 78c0abe..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
-
-    This file is part of libdcp.
-
-    libdcp 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.
-
-    libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
-
-    In addition, as a special exception, the copyright holders give
-    permission to link the code of portions of this program with the
-    OpenSSL library under certain conditions as described in each
-    individual source file, and distribute linked combinations
-    including the two.
-
-    You must obey the GNU General Public License in all respects
-    for all of the code used other than OpenSSL.  If you modify
-    file(s) with this exception, you may extend this exception to your
-    version of the file(s), but you are not obligated to do so.  If you
-    do not wish to do so, delete this exception statement from your
-    version.  If you delete this exception statement from all source
-    files in the program, then also delete it here.
-*/
-
-#include "sound_asset_reader.h"
-#include "sound_asset.h"
-#include "sound_frame.h"
-#include "exceptions.h"
-#include "dcp_assert.h"
-#include <asdcp/AS_DCP.h>
-
-using boost::shared_ptr;
-using namespace dcp;
-
-SoundAssetReader::SoundAssetReader (SoundAsset const * asset)
-       : AssetReader (asset)
-{
-       _reader = new ASDCP::PCM::MXFReader ();
-       DCP_ASSERT (asset->file ());
-       Kumu::Result_t const r = _reader->OpenRead (asset->file()->string().c_str());
-       if (ASDCP_FAILURE (r)) {
-               delete _reader;
-               boost::throw_exception (FileError ("could not open MXF file for reading", asset->file().get(), r));
-       }
-}
-
-SoundAssetReader::~SoundAssetReader ()
-{
-       delete _reader;
-}
-
-shared_ptr<const SoundFrame>
-SoundAssetReader::get_frame (int n) const
-{
-       return shared_ptr<const SoundFrame> (new SoundFrame (_reader, n, _decryption_context));
-}
index b2213b59d74effec756f00b7e775f4a044e3a0b4..41d50257a4d09ff6bb923f93eccf51838718edaf 100644 (file)
 */
 
 #include "asset_reader.h"
-#include "sound_frame.h"
-#include <boost/shared_ptr.hpp>
-
-namespace ASDCP {
-       namespace PCM {
-               class MXFReader;
-       }
-}
 
 namespace dcp {
 
-class SoundAsset;
-
-class SoundAssetReader : public AssetReader
-{
-public:
-       ~SoundAssetReader ();
-       boost::shared_ptr<const SoundFrame> get_frame (int n) const;
-
-private:
-       friend class SoundAsset;
-
-       explicit SoundAssetReader (SoundAsset const * asset);
-
-       ASDCP::PCM::MXFReader* _reader;
-};
+typedef AssetReader<ASDCP::PCM::MXFReader, SoundFrame> SoundAssetReader;
 
 }
index 23c4913839438374e49aee08904d7f11b267e6e5..fbf4e61817ef78f3bd851dd58b03ba083f4b5590 100644 (file)
 #define LIBDCP_STEREO_PICTURE_ASSET_H
 
 #include "picture_asset.h"
+#include "stereo_picture_asset_reader.h"
 
 namespace dcp {
 
-class StereoPictureAssetReader;
-
 /** A 3D (stereoscopic) picture asset */
 class StereoPictureAsset : public PictureAsset
 {
diff --git a/src/stereo_picture_asset_reader.cc b/src/stereo_picture_asset_reader.cc
deleted file mode 100644 (file)
index 7348dfa..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
-
-    This file is part of libdcp.
-
-    libdcp 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.
-
-    libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
-
-    In addition, as a special exception, the copyright holders give
-    permission to link the code of portions of this program with the
-    OpenSSL library under certain conditions as described in each
-    individual source file, and distribute linked combinations
-    including the two.
-
-    You must obey the GNU General Public License in all respects
-    for all of the code used other than OpenSSL.  If you modify
-    file(s) with this exception, you may extend this exception to your
-    version of the file(s), but you are not obligated to do so.  If you
-    do not wish to do so, delete this exception statement from your
-    version.  If you delete this exception statement from all source
-    files in the program, then also delete it here.
-*/
-
-#include "stereo_picture_asset_reader.h"
-#include "stereo_picture_asset.h"
-#include "stereo_picture_frame.h"
-#include "exceptions.h"
-#include "dcp_assert.h"
-#include <asdcp/AS_DCP.h>
-
-using namespace dcp;
-using boost::shared_ptr;
-
-StereoPictureAssetReader::StereoPictureAssetReader (StereoPictureAsset const * asset)
-       : AssetReader (asset)
-{
-       _reader = new ASDCP::JP2K::MXFSReader ();
-       DCP_ASSERT (asset->file ());
-       Kumu::Result_t const r = _reader->OpenRead (asset->file()->string().c_str());
-       if (ASDCP_FAILURE (r)) {
-               delete _reader;
-               boost::throw_exception (FileError ("could not open MXF file for reading", asset->file().get(), r));
-       }
-}
-
-StereoPictureAssetReader::~StereoPictureAssetReader ()
-{
-       delete _reader;
-}
-
-shared_ptr<const StereoPictureFrame>
-StereoPictureAssetReader::get_frame (int n) const
-{
-       return shared_ptr<const StereoPictureFrame> (new StereoPictureFrame (_reader, n, _decryption_context));
-}
index 817bc4b34f8f4097de77e44b455c16ef4908959a..43b9d2255c858e36ae532d34325284b1c2934d2f 100644 (file)
 */
 
 #include "asset_reader.h"
-#include <boost/shared_ptr.hpp>
-
-namespace ASDCP {
-       namespace JP2K {
-               class MXFSReader;
-       }
-}
 
 namespace dcp {
 
 class StereoPictureFrame;
-class StereoPictureAsset;
-
-class StereoPictureAssetReader : public AssetReader
-{
-public:
-       ~StereoPictureAssetReader ();
-       boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const;
-
-private:
-       friend class StereoPictureAsset;
-
-       explicit StereoPictureAssetReader (StereoPictureAsset const *);
 
-       ASDCP::JP2K::MXFSReader* _reader;
-};
+typedef AssetReader<ASDCP::JP2K::MXFSReader, StereoPictureFrame> StereoPictureAssetReader;
 
 }
index 65e1cea38ee04fa6dfd46e484412fc27a5ca217c..42d88b3f5c979bf6f41cf17a3f3430d8f45cd30b 100644 (file)
@@ -32,6 +32,7 @@
 */
 
 #include "types.h"
+#include "stereo_picture_asset_reader.h"
 #include <boost/shared_ptr.hpp>
 #include <boost/noncopyable.hpp>
 #include <boost/filesystem.hpp>
@@ -69,7 +70,7 @@ public:
        int right_j2k_size () const;
 
 private:
-       friend class StereoPictureAssetReader;
+       friend StereoPictureAssetReader;
 
        StereoPictureFrame (ASDCP::JP2K::MXFSReader* reader, int n, boost::shared_ptr<DecryptionContext>);
 
index dfb106be8fa667c01f35cd7cbabb50aabc3669a8..63c65905cb5ce4f57bc04320b6e539f537f34959 100644 (file)
@@ -35,7 +35,6 @@ from waflib import TaskGen
 def build(bld):
     source = """
              asset.cc
-             asset_reader.cc
              asset_writer.cc
              atmos_asset.cc
              certificate_chain.cc
@@ -64,7 +63,6 @@ def build(bld):
              metadata.cc
              modified_gamma_transfer_function.cc
              mono_picture_asset.cc
-             mono_picture_asset_reader.cc
              mono_picture_asset_writer.cc
              mono_picture_frame.cc
              mxf.cc
@@ -88,10 +86,8 @@ def build(bld):
              smpte_load_font_node.cc
              smpte_subtitle_asset.cc
              sound_asset.cc
-             sound_asset_reader.cc
              sound_asset_writer.cc
              stereo_picture_asset.cc
-             stereo_picture_asset_reader.cc
              stereo_picture_asset_writer.cc
              stereo_picture_frame.cc
              subtitle_asset.cc