diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-09-15 22:14:04 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-09-15 22:15:13 +0100 |
| commit | a6070a8af446620ab16ad172b94041601c95700d (patch) | |
| tree | ed35b7b2e3a4568497fd1bedfc2a19e43ffb887b /src | |
| parent | da2c6b70a34e68e4e6f4c680f1465bfb845ba47d (diff) | |
Move _started from PictureAssetWriter into AssetWriter
and don't start the SoundAssetWriter until the first
thing is written to it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset_writer.cc | 1 | ||||
| -rw-r--r-- | src/asset_writer.h | 2 | ||||
| -rw-r--r-- | src/picture_asset_writer.cc | 1 | ||||
| -rw-r--r-- | src/picture_asset_writer.h | 1 | ||||
| -rw-r--r-- | src/sound_asset_writer.cc | 19 |
5 files changed, 14 insertions, 10 deletions
diff --git a/src/asset_writer.cc b/src/asset_writer.cc index 4611b38a..db2d4c53 100644 --- a/src/asset_writer.cc +++ b/src/asset_writer.cc @@ -38,6 +38,7 @@ AssetWriter::AssetWriter (MXF* mxf, boost::filesystem::path file) , _file (file) , _frames_written (0) , _finalized (false) + , _started (false) , _encryption_context (0) { if (mxf->key ()) { diff --git a/src/asset_writer.h b/src/asset_writer.h index 31d2f7ae..66d7396f 100644 --- a/src/asset_writer.h +++ b/src/asset_writer.h @@ -59,6 +59,8 @@ protected: int64_t _frames_written; /** true if finalize() has been called on this object */ bool _finalized; + /** true if something has been written to this asset */ + bool _started; ASDCP::AESEncContext* _encryption_context; }; diff --git a/src/picture_asset_writer.cc b/src/picture_asset_writer.cc index b47aaabd..3bb6a597 100644 --- a/src/picture_asset_writer.cc +++ b/src/picture_asset_writer.cc @@ -34,7 +34,6 @@ using namespace dcp; PictureAssetWriter::PictureAssetWriter (PictureAsset* asset, boost::filesystem::path file, Standard standard, bool overwrite) : AssetWriter (asset, file) , _picture_asset (asset) - , _started (false) , _standard (standard) , _overwrite (overwrite) { diff --git a/src/picture_asset_writer.h b/src/picture_asset_writer.h index e263d479..a815fbcd 100644 --- a/src/picture_asset_writer.h +++ b/src/picture_asset_writer.h @@ -74,7 +74,6 @@ protected: PictureAssetWriter (PictureAsset *, boost::filesystem::path, Standard standard, bool); PictureAsset* _picture_asset; - bool _started; Standard _standard; bool _overwrite; }; diff --git a/src/sound_asset_writer.cc b/src/sound_asset_writer.cc index 4a27639e..f24605bb 100644 --- a/src/sound_asset_writer.cc +++ b/src/sound_asset_writer.cc @@ -56,13 +56,6 @@ SoundAssetWriter::SoundAssetWriter (SoundAsset* asset, boost::filesystem::path f memset (_state->frame_buffer.Data(), 0, _state->frame_buffer.Capacity()); _sound_asset->fill_writer_info (&_state->writer_info, _sound_asset->id(), standard); - - Kumu::Result_t r = _state->mxf_writer.OpenWrite (file.string().c_str(), _state->writer_info, _state->audio_desc); - if (ASDCP_FAILURE (r)) { - boost::throw_exception (FileError ("could not open audio MXF for writing", file.string(), r)); - } - - _sound_asset->set_file (file); } void @@ -70,6 +63,16 @@ SoundAssetWriter::write (float const * const * data, int frames) { DCP_ASSERT (!_finalized); + if (!_started) { + Kumu::Result_t r = _state->mxf_writer.OpenWrite (_file.string().c_str(), _state->writer_info, _state->audio_desc); + if (ASDCP_FAILURE (r)) { + boost::throw_exception (FileError ("could not open audio MXF for writing", _file.string(), r)); + } + + _sound_asset->set_file (_file); + _started = true; + } + for (int i = 0; i < frames; ++i) { byte_t* out = _state->frame_buffer.Data() + _frame_buffer_offset; @@ -112,7 +115,7 @@ SoundAssetWriter::finalize () write_current_frame (); } - if (ASDCP_FAILURE (_state->mxf_writer.Finalize())) { + if (_started && ASDCP_FAILURE (_state->mxf_writer.Finalize())) { boost::throw_exception (MiscError ("could not finalise audio MXF")); } |
