*/
-#include "sound_asset.h"
-#include "util.h"
-#include "exceptions.h"
-#include "sound_frame.h"
-#include "sound_asset_writer.h"
-#include "sound_asset_reader.h"
#include "compose.hpp"
#include "dcp_assert.h"
+#include "equality_options.h"
+#include "exceptions.h"
+#include "filesystem.h"
+#include "sound_asset.h"
+#include "sound_asset_reader.h"
+#include "sound_asset_writer.h"
+#include "sound_frame.h"
+#include "util.h"
+#include "warnings.h"
+LIBDCP_DISABLE_WARNINGS
#include <asdcp/AS_DCP.h>
#include <asdcp/KM_fileio.h>
#include <asdcp/Metadata.h>
+LIBDCP_ENABLE_WARNINGS
#include <libxml++/nodes/element.h>
#include <boost/filesystem.hpp>
#include <stdexcept>
-using std::string;
-using std::vector;
+using std::dynamic_pointer_cast;
using std::list;
using std::shared_ptr;
-using std::dynamic_pointer_cast;
+using std::string;
+using std::vector;
+using boost::optional;
using namespace dcp;
SoundAsset::SoundAsset (boost::filesystem::path file)
: Asset (file)
{
- ASDCP::PCM::MXFReader reader;
- auto r = reader.OpenRead (file.string().c_str());
+ Kumu::FileReaderFactory factory;
+ ASDCP::PCM::MXFReader reader(factory);
+ auto r = reader.OpenRead(dcp::filesystem::fix_long_path(file).string().c_str());
if (ASDCP_FAILURE(r)) {
boost::throw_exception (MXFFileError("could not open MXF file for reading", file.string(), r));
}
boost::throw_exception (ReadError("could not read audio MXF information"));
}
- _sampling_rate = desc.AudioSamplingRate.Numerator / desc.AudioSamplingRate.Denominator;
+ _sampling_rate = desc.AudioSamplingRate.Denominator ? (desc.AudioSamplingRate.Numerator / desc.AudioSamplingRate.Denominator) : 0;
_channels = desc.ChannelCount;
_edit_rate = Fraction (desc.EditRate.Numerator, desc.EditRate.Denominator);
}
}
+ list<ASDCP::MXF::InterchangeObject*> channel_labels;
+ rr = reader.OP1aHeader().GetMDObjectsByType(
+ asdcp_smpte_dict->ul(ASDCP::MDD_AudioChannelLabelSubDescriptor),
+ channel_labels
+ );
+
+ if (KM_SUCCESS(rr)) {
+ _active_channels = channel_labels.size();
+ }
+
_id = read_writer_info (info);
}
bool
-SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
+SoundAsset::equals(shared_ptr<const Asset> other, EqualityOptions const& opt, NoteHandler note) const
{
- ASDCP::PCM::MXFReader reader_A;
+ if (opt.sound_assets_can_differ) {
+ return true;
+ }
+
+ Kumu::FileReaderFactory factory;
+ ASDCP::PCM::MXFReader reader_A(factory);
DCP_ASSERT (file());
- auto r = reader_A.OpenRead (file()->string().c_str());
+ auto r = reader_A.OpenRead(dcp::filesystem::fix_long_path(*file()).string().c_str());
if (ASDCP_FAILURE(r)) {
boost::throw_exception (MXFFileError("could not open MXF file for reading", file()->string(), r));
}
- ASDCP::PCM::MXFReader reader_B;
- r = reader_B.OpenRead (other->file()->string().c_str());
+ ASDCP::PCM::MXFReader reader_B(factory);
+ r = reader_B.OpenRead(dcp::filesystem::fix_long_path(*other->file()).string().c_str());
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MXFFileError("could not open MXF file for reading", other->file()->string(), r));
}
for (int channel = 0; channel < frame_A->channels(); ++channel) {
int32_t const d = abs(frame_A->get(channel, sample) - frame_B->get(channel, sample));
if (d > opt.max_audio_sample_error) {
- note (NoteType::ERROR, String::compose ("PCM data difference of %1", d));
+ note (NoteType::ERROR, String::compose("PCM data difference of %1 in frame %2, channel %3, sample %4", d, i, channel, sample));
return false;
}
}
shared_ptr<SoundAssetWriter>
-SoundAsset::start_write (boost::filesystem::path file, bool atmos_sync)
+SoundAsset::start_write(
+ boost::filesystem::path file,
+ vector<dcp::Channel> extra_active_channels,
+ AtmosSync atmos_sync,
+ MCASubDescriptors include_mca_subdescriptors
+ )
{
- if (atmos_sync && _channels < 14) {
+ if (atmos_sync == AtmosSync::ENABLED && _channels < 14) {
throw MiscError ("Insufficient channels to write ATMOS sync (there must be at least 14)");
}
- return shared_ptr<SoundAssetWriter> (new SoundAssetWriter(this, file, atmos_sync));
+ return shared_ptr<SoundAssetWriter>(
+ new SoundAssetWriter(this, file, extra_active_channels, atmos_sync == AtmosSync::ENABLED, include_mca_subdescriptors == MCASubDescriptors::ENABLED)
+ );
}
bool
SoundAsset::valid_mxf (boost::filesystem::path file)
{
- ASDCP::PCM::MXFReader reader;
- Kumu::Result_t r = reader.OpenRead (file.string().c_str());
+ Kumu::FileReaderFactory factory;
+ ASDCP::PCM::MXFReader reader(factory);
+ Kumu::Result_t r = reader.OpenRead(dcp::filesystem::fix_long_path(file).string().c_str());
return !ASDCP_FAILURE (r);
}
+
+
+int
+SoundAsset::active_channels() const
+{
+ return _active_channels.get_value_or(_channels);
+}
+