#include "exceptions.h"
#include "dcp_assert.h"
#include "compose.hpp"
-#include "encryption_context.h"
+#include "crypto_context.h"
#include <asdcp/AS_DCP.h>
+#include <iostream>
using std::min;
using std::max;
+using std::cout;
using namespace dcp;
struct SoundAssetWriter::ASDCPState
ASDCP::PCM::AudioDescriptor desc;
};
-SoundAssetWriter::SoundAssetWriter (SoundAsset* asset, boost::filesystem::path file, Standard standard)
- : AssetWriter (asset, file, standard)
+SoundAssetWriter::SoundAssetWriter (SoundAsset* asset, boost::filesystem::path file)
+ : AssetWriter (asset, file)
, _state (new SoundAssetWriter::ASDCPState)
, _asset (asset)
, _frame_buffer_offset (0)
_state->desc.BlockAlign = 3 * _asset->channels();
_state->desc.AvgBps = _asset->sampling_rate() * _state->desc.BlockAlign;
_state->desc.LinkedTrackID = 0;
- if (standard == INTEROP) {
+ if (asset->standard() == INTEROP) {
_state->desc.ChannelFormat = ASDCP::PCM::CF_NONE;
} else {
/* Just use WTF ("wild track format") for SMPTE for now; searches suggest that this
_state->desc.ChannelFormat = ASDCP::PCM::CF_CFG_4;
}
+ /* I'm fairly sure this is not necessary, as ContainerDuration is written
+ in ASDCP's WriteMXFFooter, but it stops a valgrind warning.
+ */
+ _state->desc.ContainerDuration = 0;
+
_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());
- _asset->fill_writer_info (&_state->writer_info, _asset->id(), standard);
+ _asset->fill_writer_info (&_state->writer_info, _asset->id());
}
void
SoundAssetWriter::write (float const * const * data, int frames)
{
DCP_ASSERT (!_finalized);
+ DCP_ASSERT (frames > 0);
static float const clip = 1.0f - (1.0f / pow (2, 23));
void
SoundAssetWriter::write_current_frame ()
{
- ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context->encryption(), _encryption_context->hmac());
+ ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _crypto_context->context(), _crypto_context->hmac());
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MiscError (String::compose ("could not write audio MXF frame (%1)", int (r))));
}
write_current_frame ();
}
- if (_started && ASDCP_FAILURE (_state->mxf_writer.Finalize())) {
- boost::throw_exception (MiscError ("could not finalise audio MXF"));
+ if (_started) {
+ ASDCP::Result_t const r = _state->mxf_writer.Finalize();
+ if (ASDCP_FAILURE(r)) {
+ boost::throw_exception (MiscError (String::compose ("could not finalise audio MXF (%1)", int(r))));
+ }
}
_asset->_intrinsic_duration = _frames_written;