#include <iostream>
#include <stdexcept>
#include <boost/filesystem.hpp>
+#include <boost/lexical_cast.hpp>
+#include "KM_fileio.h"
#include "AS_DCP.h"
#include "sound_asset.h"
#include "util.h"
using namespace libdcp;
SoundAsset::SoundAsset (
- vector<string> const & files, string mxf_path, sigc::signal1<void, float>* progress, int fps, int length
+ vector<string> const & files, string directory, string mxf_name, sigc::signal1<void, float>* progress, int fps, int length
)
- : Asset (mxf_path, progress, fps, length)
+ : Asset (directory, mxf_name, progress, fps, length)
, _channels (files.size ())
{
construct (sigc::bind (sigc::mem_fun (*this, &SoundAsset::path_from_channel), files));
}
SoundAsset::SoundAsset (
- sigc::slot<string, Channel> get_path, string mxf_path, sigc::signal1<void, float>* progress, int fps, int length, int channels
+ sigc::slot<string, Channel> get_path, string directory, string mxf_name, sigc::signal1<void, float>* progress, int fps, int length, int channels
)
- : Asset (mxf_path, progress, fps, length)
+ : Asset (directory, mxf_name, progress, fps, length)
, _channels (channels)
{
construct (get_path);
}
-SoundAsset::SoundAsset (string mxf_path, int fps, int length)
- : Asset (mxf_path, 0, fps, length)
+SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int length)
+ : Asset (directory, mxf_name, 0, fps, length)
, _channels (0)
{
fill_writer_info (&writer_info);
ASDCP::PCM::MXFWriter mxf_writer;
- if (ASDCP_FAILURE (mxf_writer.OpenWrite (_mxf_path.c_str(), writer_info, audio_desc))) {
- throw FileError ("could not open audio MXF for writing", _mxf_path);
+ if (ASDCP_FAILURE (mxf_writer.OpenWrite (mxf_path().string().c_str(), writer_info, audio_desc))) {
+ throw FileError ("could not open audio MXF for writing", mxf_path().string());
}
for (int i = 0; i < _length; ++i) {
if (ASDCP_FAILURE (mxf_writer.Finalize())) {
throw MiscError ("could not finalise audio MXF");
}
-
- _digest = make_digest (_mxf_path, _progress);
}
void
{
s << " <MainSound>\n"
<< " <Id>urn:uuid:" << _uuid << "</Id>\n"
-#if BOOST_FILESYSTEM_VERSION == 3
- << " <AnnotationText>" << filesystem::path(_mxf_path).filename().string() << "</AnnotationText>\n"
-#else
- << " <AnnotationText>" << filesystem::path(_mxf_path).filename() << "</AnnotationText>\n"
-#endif
+ << " <AnnotationText>" << _mxf_name << "</AnnotationText>\n"
<< " <EditRate>" << _fps << " 1</EditRate>\n"
<< " <IntrinsicDuration>" << _length << "</IntrinsicDuration>\n"
<< " <EntryPoint>0</EntryPoint>\n"
<< " </MainSound>\n";
}
+list<string>
+SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
+{
+ list<string> notes = Asset::equals (other, opt);
+
+ if (opt.flags & MXF_INSPECT) {
+ ASDCP::PCM::MXFReader reader_A;
+ if (ASDCP_FAILURE (reader_A.OpenRead (mxf_path().string().c_str()))) {
+ cout << "failed " << mxf_path() << "\n";
+ throw FileError ("could not open MXF file for reading", mxf_path().string());
+ }
+
+ ASDCP::PCM::MXFReader reader_B;
+ if (ASDCP_FAILURE (reader_B.OpenRead (other->mxf_path().string().c_str()))) {
+ cout << "failed " << other->mxf_path() << "\n";
+ throw FileError ("could not open MXF file for reading", mxf_path().string());
+ }
+
+ ASDCP::PCM::AudioDescriptor desc_A;
+ if (ASDCP_FAILURE (reader_A.FillAudioDescriptor (desc_A))) {
+ throw DCPReadError ("could not read audio MXF information");
+ }
+ ASDCP::PCM::AudioDescriptor desc_B;
+ if (ASDCP_FAILURE (reader_B.FillAudioDescriptor (desc_B))) {
+ throw DCPReadError ("could not read audio MXF information");
+ }
+
+ if (
+ desc_A.EditRate != desc_B.EditRate ||
+ desc_A.AudioSamplingRate != desc_B.AudioSamplingRate ||
+ desc_A.Locked != desc_B.Locked ||
+ desc_A.ChannelCount != desc_B.ChannelCount ||
+ desc_A.QuantizationBits != desc_B.QuantizationBits ||
+ desc_A.BlockAlign != desc_B.BlockAlign ||
+ desc_A.AvgBps != desc_B.AvgBps ||
+ desc_A.LinkedTrackID != desc_B.LinkedTrackID ||
+ desc_A.ContainerDuration != desc_B.ContainerDuration
+// desc_A.ChannelFormat != desc_B.ChannelFormat ||
+ ) {
+
+ notes.push_back ("audio MXF picture descriptors differ");
+ }
+
+ ASDCP::PCM::FrameBuffer buffer_A (1 * Kumu::Megabyte);
+ ASDCP::PCM::FrameBuffer buffer_B (1 * Kumu::Megabyte);
+
+ for (int i = 0; i < _length; ++i) {
+ if (ASDCP_FAILURE (reader_A.ReadFrame (0, buffer_A))) {
+ throw DCPReadError ("could not read audio frame");
+ }
+
+ if (ASDCP_FAILURE (reader_B.ReadFrame (0, buffer_B))) {
+ throw DCPReadError ("could not read audio frame");
+ }
+
+ if (buffer_A.Size() != buffer_B.Size()) {
+ notes.push_back ("sizes of video data for frame " + lexical_cast<string>(i) + " differ");
+ continue;
+ }
+
+ if (memcmp (buffer_A.RoData(), buffer_B.RoData(), buffer_A.Size()) != 0) {
+ notes.push_back ("PCM data for frame " + lexical_cast<string>(i) + " differ");
+ continue;
+ }
+ }
+ }
+
+ return notes;
+}