diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-09-27 11:35:53 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-09-27 11:35:53 +0100 |
| commit | f9474637db140eb3d9170185fc79437c8d9914b7 (patch) | |
| tree | 9f9e9eeaea1dd52c50f21869d8cb5e948787c4b7 /src | |
| parent | 8c7b705e318d888444e5156f627cdc48168d3ac7 (diff) | |
Use a template for AssetReader.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset_reader.cc | 46 | ||||
| -rw-r--r-- | src/asset_reader.h | 28 | ||||
| -rw-r--r-- | src/mono_picture_asset.h | 2 | ||||
| -rw-r--r-- | src/mono_picture_asset_reader.cc | 65 | ||||
| -rw-r--r-- | src/mono_picture_asset_reader.h | 22 | ||||
| -rw-r--r-- | src/mono_picture_frame.h | 3 | ||||
| -rw-r--r-- | src/sound_asset.h | 2 | ||||
| -rw-r--r-- | src/sound_asset_reader.cc | 65 | ||||
| -rw-r--r-- | src/sound_asset_reader.h | 24 | ||||
| -rw-r--r-- | src/stereo_picture_asset.h | 3 | ||||
| -rw-r--r-- | src/stereo_picture_asset_reader.cc | 65 | ||||
| -rw-r--r-- | src/stereo_picture_asset_reader.h | 22 | ||||
| -rw-r--r-- | src/stereo_picture_frame.h | 3 | ||||
| -rw-r--r-- | src/wscript | 4 |
14 files changed, 35 insertions, 319 deletions
diff --git a/src/asset_reader.cc b/src/asset_reader.cc deleted file mode 100644 index 73c5d010..00000000 --- a/src/asset_reader.cc +++ /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 ())) -{ - -} diff --git a/src/asset_reader.h b/src/asset_reader.h index 09169a8e..1cfd9ea2 100644 --- a/src/asset_reader.h +++ b/src/asset_reader.h @@ -34,21 +34,43 @@ #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; }; diff --git a/src/mono_picture_asset.h b/src/mono_picture_asset.h index 75ebc3aa..f532db00 100644 --- a/src/mono_picture_asset.h +++ b/src/mono_picture_asset.h @@ -35,11 +35,11 @@ #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 index f11ec7f4..00000000 --- a/src/mono_picture_asset_reader.cc +++ /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)); -} diff --git a/src/mono_picture_asset_reader.h b/src/mono_picture_asset_reader.h index 08f9fde0..9ec899cc 100644 --- a/src/mono_picture_asset_reader.h +++ b/src/mono_picture_asset_reader.h @@ -32,31 +32,11 @@ */ #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; } diff --git a/src/mono_picture_frame.h b/src/mono_picture_frame.h index cb4afd6f..87c5d6ab 100644 --- a/src/mono_picture_frame.h +++ b/src/mono_picture_frame.h @@ -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>); diff --git a/src/sound_asset.h b/src/sound_asset.h index 9278eeee..6d090312 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -42,12 +42,12 @@ #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 index 78c0abe1..00000000 --- a/src/sound_asset_reader.cc +++ /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)); -} diff --git a/src/sound_asset_reader.h b/src/sound_asset_reader.h index b2213b59..41d50257 100644 --- a/src/sound_asset_reader.h +++ b/src/sound_asset_reader.h @@ -32,31 +32,9 @@ */ #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; } diff --git a/src/stereo_picture_asset.h b/src/stereo_picture_asset.h index 23c49138..fbf4e618 100644 --- a/src/stereo_picture_asset.h +++ b/src/stereo_picture_asset.h @@ -35,11 +35,10 @@ #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 index 7348dfa9..00000000 --- a/src/stereo_picture_asset_reader.cc +++ /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)); -} diff --git a/src/stereo_picture_asset_reader.h b/src/stereo_picture_asset_reader.h index 817bc4b3..43b9d225 100644 --- a/src/stereo_picture_asset_reader.h +++ b/src/stereo_picture_asset_reader.h @@ -32,31 +32,11 @@ */ #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; } diff --git a/src/stereo_picture_frame.h b/src/stereo_picture_frame.h index 65e1cea3..42d88b3f 100644 --- a/src/stereo_picture_frame.h +++ b/src/stereo_picture_frame.h @@ -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>); diff --git a/src/wscript b/src/wscript index dfb106be..63c65905 100644 --- a/src/wscript +++ b/src/wscript @@ -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 |
