diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-09-28 19:15:03 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-09-28 19:15:03 +0100 |
| commit | eb772d227c378e17c99b5d609b81d0cc4b664d2c (patch) | |
| tree | ccc3b4c75316d76fd441767e29ed1e0d8d3908a6 /src | |
| parent | fba372ef15a9dd9c6f840e5c03bdb85146657955 (diff) | |
| parent | 5aba207171b7f1da91968bf2197c5668e8aacb4e (diff) | |
Merge branch '1.0' of ssh://main.carlh.net/home/carl/git/libdcp into 1.0
Diffstat (limited to 'src')
25 files changed, 322 insertions, 293 deletions
diff --git a/src/asset_reader.h b/src/asset_reader.h index 09169a8e..eaf2721a 100644 --- a/src/asset_reader.h +++ b/src/asset_reader.h @@ -34,21 +34,45 @@ #ifndef LIBDCP_ASSET_READER_H #define LIBDCP_ASSET_READER_H +#include "dcp_assert.h" +#include "asset.h" +#include "decryption_context.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, boost::optional<Key> key) + : _decryption_context (new DecryptionContext (key)) + { + _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/atmos_asset.cc b/src/atmos_asset.cc index a8a595c3..eac01dcf 100644 --- a/src/atmos_asset.cc +++ b/src/atmos_asset.cc @@ -32,12 +32,27 @@ */ #include "atmos_asset.h" +#include "atmos_asset_reader.h" +#include "atmos_asset_writer.h" #include "exceptions.h" #include <asdcp/AS_DCP.h> using std::string; +using boost::shared_ptr; using namespace dcp; +AtmosAsset::AtmosAsset (Fraction edit_rate, int first_frame, int max_channel_count, int max_object_count, string atmos_id, int atmos_version) + : _edit_rate (edit_rate) + , _intrinsic_duration (0) + , _first_frame (first_frame) + , _max_channel_count (max_channel_count) + , _max_object_count (max_object_count) + , _atmos_id (atmos_id) + , _atmos_version (atmos_version) +{ + +} + AtmosAsset::AtmosAsset (boost::filesystem::path file) : Asset (file) { @@ -57,6 +72,12 @@ AtmosAsset::AtmosAsset (boost::filesystem::path file) _first_frame = desc.FirstFrame; _max_channel_count = desc.MaxChannelCount; _max_object_count = desc.MaxObjectCount; + + char id[64]; + Kumu::bin2UUIDhex (desc.AtmosID, ASDCP::UUIDlen, id, sizeof (id)); + _atmos_id = id; + + _atmos_version = desc.AtmosVersion; } string @@ -64,3 +85,15 @@ AtmosAsset::pkl_type (Standard) const { return "application/mxf"; } + +shared_ptr<AtmosAssetReader> +AtmosAsset::start_read () const +{ + return shared_ptr<AtmosAssetReader> (new AtmosAssetReader (this, key ())); +} + +shared_ptr<AtmosAssetWriter> +AtmosAsset::start_write (boost::filesystem::path file) +{ + return shared_ptr<AtmosAssetWriter> (new AtmosAssetWriter (this, file)); +} diff --git a/src/atmos_asset.h b/src/atmos_asset.h index 2e99e18b..8e9190c8 100644 --- a/src/atmos_asset.h +++ b/src/atmos_asset.h @@ -36,14 +36,21 @@ #include "asset.h" #include "mxf.h" +#include "atmos_asset_reader.h" namespace dcp { +class AtmosAssetWriter; + class AtmosAsset : public Asset, public MXF { public: + AtmosAsset (Fraction edit_rate, int first_frame, int max_channel_count, int max_object_count, std::string atmos_id, int atmos_version); explicit AtmosAsset (boost::filesystem::path file); + boost::shared_ptr<AtmosAssetWriter> start_write (boost::filesystem::path file); + boost::shared_ptr<AtmosAssetReader> start_read () const; + std::string pkl_type (Standard) const; Fraction edit_rate () const { @@ -69,12 +76,24 @@ public: return _max_object_count; } + std::string atmos_id () const { + return _atmos_id; + } + + int atmos_version () const { + return _atmos_version; + } + private: + friend class AtmosAssetWriter; + Fraction _edit_rate; int64_t _intrinsic_duration; int _first_frame; int _max_channel_count; int _max_object_count; + std::string _atmos_id; + int _atmos_version; }; } diff --git a/src/asset_reader.cc b/src/atmos_asset_reader.h index 73c5d010..14806261 100644 --- a/src/asset_reader.cc +++ b/src/atmos_asset_reader.h @@ -32,15 +32,10 @@ */ #include "asset_reader.h" -#include "mxf.h" -#include "exceptions.h" -#include "decryption_context.h" -#include <asdcp/AS_DCP.h> +#include "atmos_frame.h" -using namespace dcp; +namespace dcp { -AssetReader::AssetReader (MXF const * mxf) - : _decryption_context (new DecryptionContext (mxf->key ())) -{ +typedef AssetReader<ASDCP::ATMOS::MXFReader, AtmosFrame> AtmosAssetReader; } diff --git a/src/atmos_asset_writer.cc b/src/atmos_asset_writer.cc new file mode 100644 index 00000000..eb0d608a --- /dev/null +++ b/src/atmos_asset_writer.cc @@ -0,0 +1,109 @@ +/* + 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 "atmos_asset_writer.h" +#include "atmos_asset.h" +#include "exceptions.h" +#include "dcp_assert.h" +#include "compose.hpp" +#include "encryption_context.h" +#include <asdcp/AS_DCP.h> + +using std::min; +using std::max; +using namespace dcp; + +struct AtmosAssetWriter::ASDCPState +{ + ASDCP::ATMOS::MXFWriter mxf_writer; + ASDCP::DCData::FrameBuffer frame_buffer; + ASDCP::WriterInfo writer_info; + ASDCP::ATMOS::AtmosDescriptor desc; +}; + +AtmosAssetWriter::AtmosAssetWriter (AtmosAsset* asset, boost::filesystem::path file) + : AssetWriter (asset, file, SMPTE) + , _state (new AtmosAssetWriter::ASDCPState) + , _asset (asset) +{ + _state->desc.EditRate = ASDCP::Rational (_asset->edit_rate().numerator, _asset->edit_rate().denominator); + _state->desc.FirstFrame = _asset->first_frame (); + _state->desc.MaxChannelCount = _asset->max_channel_count (); + _state->desc.MaxObjectCount = _asset->max_object_count (); + + unsigned int c; + Kumu::hex2bin (_asset->atmos_id().c_str(), _state->desc.AtmosID, ASDCP::UUIDlen, &c); + DCP_ASSERT (c == ASDCP::UUIDlen); + + _state->desc.AtmosVersion = 0; + + _asset->fill_writer_info (&_state->writer_info, _asset->id(), SMPTE); +} + +void +AtmosAssetWriter::write (uint8_t const * data, int size) +{ + DCP_ASSERT (!_finalized); + + if (!_started) { + Kumu::Result_t r = _state->mxf_writer.OpenWrite (_file.string().c_str(), _state->writer_info, _state->desc); + if (ASDCP_FAILURE (r)) { + boost::throw_exception (FileError ("could not open atmos MXF for writing", _file.string(), r)); + } + + _asset->set_file (_file); + _started = true; + } + + _state->frame_buffer.Capacity (size); + _state->frame_buffer.Size (size); + memcpy (_state->frame_buffer.Data(), data, size); + + ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context->encryption(), _encryption_context->hmac()); + if (ASDCP_FAILURE (r)) { + boost::throw_exception (MiscError (String::compose ("could not write atmos MXF frame (%1)", int (r)))); + } + + ++_frames_written; +} + +bool +AtmosAssetWriter::finalize () +{ + if (_started && ASDCP_FAILURE (_state->mxf_writer.Finalize())) { + boost::throw_exception (MiscError ("could not finalise atmos MXF")); + } + + _asset->_intrinsic_duration = _frames_written; + return AssetWriter::finalize (); +} diff --git a/src/sound_asset_reader.cc b/src/atmos_asset_writer.h index 78c0abe1..e494b779 100644 --- a/src/sound_asset_reader.cc +++ b/src/atmos_asset_writer.h @@ -31,35 +31,43 @@ 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)); - } -} +/** @file src/atmos_asset_writer.h + * @brief AtmosAssetWriter class. + */ -SoundAssetReader::~SoundAssetReader () -{ - delete _reader; -} +#include "asset_writer.h" +#include "types.h" +#include "atmos_frame.h" +#include <boost/shared_ptr.hpp> +#include <boost/filesystem.hpp> + +namespace dcp { + +class AtmosAsset; -shared_ptr<const SoundFrame> -SoundAssetReader::get_frame (int n) const +/** @class AtmosAssetWriter + * @brief A helper class for writing to AtmosAssets. + * + * Objects of this class can only be created with AtmosAsset::start_write(). + */ +class AtmosAssetWriter : public AssetWriter { - return shared_ptr<const SoundFrame> (new SoundFrame (_reader, n, _decryption_context)); +public: + void write (uint8_t const * data, int size); + bool finalize (); + +private: + friend class AtmosAsset; + + AtmosAssetWriter (AtmosAsset *, boost::filesystem::path); + + /* do this with an opaque pointer so we don't have to include + ASDCP headers + */ + struct ASDCPState; + boost::shared_ptr<ASDCPState> _state; + + AtmosAsset* _asset; +}; + } diff --git a/src/mono_picture_asset_reader.cc b/src/atmos_frame.h index f11ec7f4..763875bd 100644 --- a/src/mono_picture_asset_reader.cc +++ b/src/atmos_frame.h @@ -31,35 +31,19 @@ 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> +/** @file src/atmos_frame.h + * @brief AtmosFrame class. + */ -using namespace dcp; -using boost::shared_ptr; +#ifndef LIBDCP_ATMOS_FRAME_H +#define LIBDCP_ATMOS_FRAME_H -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)); - } -} +#include "frame.h" -MonoPictureAssetReader::~MonoPictureAssetReader () -{ - delete _reader; -} +namespace dcp { + +typedef Frame<ASDCP::ATMOS::MXFReader, ASDCP::DCData::FrameBuffer> AtmosFrame; -shared_ptr<const MonoPictureFrame> -MonoPictureAssetReader::get_frame (int n) const -{ - return shared_ptr<const MonoPictureFrame> (new MonoPictureFrame (_reader, n, _decryption_context)); } + +#endif diff --git a/src/decryption_context.h b/src/decryption_context.h index e3d3ce1e..fb8342cf 100644 --- a/src/decryption_context.h +++ b/src/decryption_context.h @@ -31,6 +31,9 @@ files in the program, then also delete it here. */ +#ifndef LIBDCP_DECRYPTION_CONTEXT_H +#define LIBDCP_DECRYPTION_CONTEXT_H + #include "key.h" #include <boost/optional.hpp> @@ -55,3 +58,5 @@ private: }; } + +#endif diff --git a/src/sound_frame.cc b/src/frame.h index 132d25bd..f20a1bb3 100644 --- a/src/sound_frame.cc +++ b/src/frame.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016 Carl Hetherington <cth@carlh.net> This file is part of libdcp. @@ -31,42 +31,50 @@ files in the program, then also delete it here. */ -/** @file src/sound_frame.cc - * @brief SoundFrame class. - */ +#ifndef LIBDCP_FRAME_H +#define LIBDCP_FRAME_H -#include "sound_frame.h" -#include "exceptions.h" #include "decryption_context.h" -#include <asdcp/AS_DCP.h> +#include "exceptions.h" #include <asdcp/KM_fileio.h> +#include <asdcp/AS_DCP.h> +#include <boost/noncopyable.hpp> -using namespace dcp; -using boost::shared_ptr; +namespace dcp { -SoundFrame::SoundFrame (ASDCP::PCM::MXFReader* reader, int n, shared_ptr<DecryptionContext> c) +template <class R, class B> +class Frame : public boost::noncopyable { - /* XXX: unfortunate guesswork on this buffer size */ - _buffer = new ASDCP::PCM::FrameBuffer (1 * Kumu::Megabyte); +public: + Frame (R* reader, int n, boost::shared_ptr<const DecryptionContext> c) + { + /* XXX: unfortunate guesswork on this buffer size */ + _buffer = new B (Kumu::Megabyte); - if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c->decryption()))) { - boost::throw_exception (DCPReadError ("could not read audio frame")); + if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c->decryption()))) { + boost::throw_exception (DCPReadError ("could not read frame")); + } } -} -SoundFrame::~SoundFrame () -{ - delete _buffer; -} + ~Frame () + { + delete _buffer; + } -uint8_t const * -SoundFrame::data () const -{ - return _buffer->RoData(); -} + uint8_t const * data () const + { + return _buffer->RoData (); + } + + int size () const + { + return _buffer->Size (); + } + +private: + B* _buffer; +}; -int -SoundFrame::size () const -{ - return _buffer->Size (); } + +#endif diff --git a/src/mono_picture_asset.cc b/src/mono_picture_asset.cc index a6643bc0..407a3614 100644 --- a/src/mono_picture_asset.cc +++ b/src/mono_picture_asset.cc @@ -176,7 +176,7 @@ MonoPictureAsset::start_write (boost::filesystem::path file, Standard standard, shared_ptr<MonoPictureAssetReader> MonoPictureAsset::start_read () const { - return shared_ptr<MonoPictureAssetReader> (new MonoPictureAssetReader (this)); + return shared_ptr<MonoPictureAssetReader> (new MonoPictureAssetReader (this, key ())); } string 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.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.cc b/src/sound_asset.cc index 11fd4b2f..74d41212 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -201,7 +201,7 @@ SoundAsset::start_write (boost::filesystem::path file, Standard standard) shared_ptr<SoundAssetReader> SoundAsset::start_read () const { - return shared_ptr<SoundAssetReader> (new SoundAssetReader (this)); + return shared_ptr<SoundAssetReader> (new SoundAssetReader (this, key ())); } string diff --git a/src/sound_asset.h b/src/sound_asset.h index a29eecd0..6d090312 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -41,13 +41,13 @@ #include "mxf.h" #include "types.h" #include "metadata.h" +#include "sound_frame.h" +#include "sound_asset_reader.h" namespace dcp { -class SoundFrame; class SoundAssetWriter; -class SoundAssetReader; /** @class SoundAsset * @brief Representation of a sound asset diff --git a/src/sound_asset_reader.h b/src/sound_asset_reader.h index 5a02322c..41d50257 100644 --- a/src/sound_asset_reader.h +++ b/src/sound_asset_reader.h @@ -32,31 +32,9 @@ */ #include "asset_reader.h" -#include <boost/shared_ptr.hpp> - -namespace ASDCP { - namespace PCM { - class MXFReader; - } -} namespace dcp { -class SoundFrame; -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/sound_asset_writer.cc b/src/sound_asset_writer.cc index 92855db7..e084d0d5 100644 --- a/src/sound_asset_writer.cc +++ b/src/sound_asset_writer.cc @@ -48,38 +48,38 @@ struct SoundAssetWriter::ASDCPState ASDCP::PCM::MXFWriter mxf_writer; ASDCP::PCM::FrameBuffer frame_buffer; ASDCP::WriterInfo writer_info; - ASDCP::PCM::AudioDescriptor audio_desc; + ASDCP::PCM::AudioDescriptor desc; }; SoundAssetWriter::SoundAssetWriter (SoundAsset* asset, boost::filesystem::path file, Standard standard) : AssetWriter (asset, file, standard) , _state (new SoundAssetWriter::ASDCPState) - , _sound_asset (asset) + , _asset (asset) , _frame_buffer_offset (0) { /* Derived from ASDCP::Wav::SimpleWaveHeader::FillADesc */ - _state->audio_desc.EditRate = ASDCP::Rational (_sound_asset->edit_rate().numerator, _sound_asset->edit_rate().denominator); - _state->audio_desc.AudioSamplingRate = ASDCP::Rational (_sound_asset->sampling_rate(), 1); - _state->audio_desc.Locked = 0; - _state->audio_desc.ChannelCount = _sound_asset->channels (); - _state->audio_desc.QuantizationBits = 24; - _state->audio_desc.BlockAlign = 3 * _sound_asset->channels(); - _state->audio_desc.AvgBps = _sound_asset->sampling_rate() * _state->audio_desc.BlockAlign; - _state->audio_desc.LinkedTrackID = 0; + _state->desc.EditRate = ASDCP::Rational (_asset->edit_rate().numerator, _asset->edit_rate().denominator); + _state->desc.AudioSamplingRate = ASDCP::Rational (_asset->sampling_rate(), 1); + _state->desc.Locked = 0; + _state->desc.ChannelCount = _asset->channels (); + _state->desc.QuantizationBits = 24; + _state->desc.BlockAlign = 3 * _asset->channels(); + _state->desc.AvgBps = _asset->sampling_rate() * _state->desc.BlockAlign; + _state->desc.LinkedTrackID = 0; if (standard == INTEROP) { - _state->audio_desc.ChannelFormat = ASDCP::PCM::CF_NONE; + _state->desc.ChannelFormat = ASDCP::PCM::CF_NONE; } else { /* Just use WTF ("wild track format") for SMPTE for now; searches suggest that this uses the same assignment as Interop. */ - _state->audio_desc.ChannelFormat = ASDCP::PCM::CF_CFG_4; + _state->desc.ChannelFormat = ASDCP::PCM::CF_CFG_4; } - _state->frame_buffer.Capacity (ASDCP::PCM::CalcFrameBufferSize (_state->audio_desc)); - _state->frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (_state->audio_desc)); + _state->frame_buffer.Capacity (ASDCP::PCM::CalcFrameBufferSize (_state->desc)); + _state->frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (_state->desc)); memset (_state->frame_buffer.Data(), 0, _state->frame_buffer.Capacity()); - _sound_asset->fill_writer_info (&_state->writer_info, _sound_asset->id(), standard); + _asset->fill_writer_info (&_state->writer_info, _asset->id(), standard); } void @@ -90,16 +90,16 @@ SoundAssetWriter::write (float const * const * data, int frames) static float const clip = 1.0f - (1.0f / pow (2, 23)); if (!_started) { - Kumu::Result_t r = _state->mxf_writer.OpenWrite (_file.string().c_str(), _state->writer_info, _state->audio_desc); + Kumu::Result_t r = _state->mxf_writer.OpenWrite (_file.string().c_str(), _state->writer_info, _state->desc); if (ASDCP_FAILURE (r)) { boost::throw_exception (FileError ("could not open audio MXF for writing", _file.string(), r)); } - _sound_asset->set_file (_file); + _asset->set_file (_file); _started = true; } - int const ch = _sound_asset->channels (); + int const ch = _asset->channels (); for (int i = 0; i < frames; ++i) { @@ -154,6 +154,6 @@ SoundAssetWriter::finalize () boost::throw_exception (MiscError ("could not finalise audio MXF")); } - _sound_asset->_intrinsic_duration = _frames_written; + _asset->_intrinsic_duration = _frames_written; return AssetWriter::finalize (); } diff --git a/src/sound_asset_writer.h b/src/sound_asset_writer.h index 02639423..0a7d8cda 100644 --- a/src/sound_asset_writer.h +++ b/src/sound_asset_writer.h @@ -37,12 +37,12 @@ #include "asset_writer.h" #include "types.h" +#include "sound_frame.h" #include <boost/shared_ptr.hpp> #include <boost/filesystem.hpp> namespace dcp { -class SoundFrame; class SoundAsset; /** @class SoundAssetWriter @@ -74,7 +74,7 @@ private: struct ASDCPState; boost::shared_ptr<ASDCPState> _state; - SoundAsset* _sound_asset; + SoundAsset* _asset; int _frame_buffer_offset; }; diff --git a/src/sound_frame.h b/src/sound_frame.h index 3cd3246b..2b78c8e1 100644 --- a/src/sound_frame.h +++ b/src/sound_frame.h @@ -38,42 +38,12 @@ #ifndef LIBDCP_SOUND_FRAME_H #define LIBDCP_SOUND_FRAME_H -#include <boost/noncopyable.hpp> -#include <boost/filesystem.hpp> -#include <stdint.h> -#include <string> - -namespace ASDCP { - namespace PCM { - class FrameBuffer; - class MXFReader; - } - class AESDecContext; -} +#include "frame.h" +#include <asdcp/AS_DCP.h> namespace dcp { -class DecryptionContext; - -/** @class SoundFrame - * @brief One ‘frame’ of sound data from a SoundAsset. - */ -class SoundFrame : public boost::noncopyable -{ -public: - ~SoundFrame (); - - uint8_t const * data () const; - int size () const; - -private: - friend class SoundAssetReader; - - SoundFrame (ASDCP::PCM::MXFReader* reader, int n, boost::shared_ptr<DecryptionContext>); - - /** a buffer to hold the frame */ - ASDCP::PCM::FrameBuffer* _buffer; -}; +typedef Frame<ASDCP::PCM::MXFReader, ASDCP::PCM::FrameBuffer> SoundFrame; } diff --git a/src/stereo_picture_asset.cc b/src/stereo_picture_asset.cc index 9a21b72b..4bbf7268 100644 --- a/src/stereo_picture_asset.cc +++ b/src/stereo_picture_asset.cc @@ -86,7 +86,7 @@ StereoPictureAsset::start_write (boost::filesystem::path file, Standard standard shared_ptr<StereoPictureAssetReader> StereoPictureAsset::start_read () const { - return shared_ptr<StereoPictureAssetReader> (new StereoPictureAssetReader (this)); + return shared_ptr<StereoPictureAssetReader> (new StereoPictureAssetReader (this, key ())); } bool 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 489d669e..9972076d 100644 --- a/src/wscript +++ b/src/wscript @@ -35,9 +35,9 @@ from waflib import TaskGen def build(bld): source = """ asset.cc - asset_reader.cc asset_writer.cc atmos_asset.cc + atmos_asset_writer.cc certificate_chain.cc certificate.cc colour_conversion.cc @@ -64,7 +64,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,11 +87,8 @@ def build(bld): smpte_load_font_node.cc smpte_subtitle_asset.cc sound_asset.cc - sound_asset_reader.cc sound_asset_writer.cc - sound_frame.cc stereo_picture_asset.cc - stereo_picture_asset_reader.cc stereo_picture_asset_writer.cc stereo_picture_frame.cc subtitle_asset.cc @@ -108,6 +104,8 @@ def build(bld): asset_reader.h asset_writer.h atmos_asset.h + atmos_asset_reader.h + atmos_asset_writer.h certificate_chain.h certificate.h chromaticity.h @@ -115,10 +113,12 @@ def build(bld): colour_matrix.h cpl.h dcp.h + dcp_assert.h dcp_time.h data.h decrypted_kdm.h decrypted_kdm_key.h + decryption_context.h encrypted_kdm.h encryption_context.h exceptions.h |
