summaryrefslogtreecommitdiff
path: root/src/sound_asset_writer.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-09-15 22:14:04 +0100
committerCarl Hetherington <cth@carlh.net>2015-09-15 22:15:13 +0100
commita6070a8af446620ab16ad172b94041601c95700d (patch)
treeed35b7b2e3a4568497fd1bedfc2a19e43ffb887b /src/sound_asset_writer.cc
parentda2c6b70a34e68e4e6f4c680f1465bfb845ba47d (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/sound_asset_writer.cc')
-rw-r--r--src/sound_asset_writer.cc19
1 files changed, 11 insertions, 8 deletions
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"));
}