40 #include "mono_picture_asset.h"
46 #include "compose.hpp"
47 #include <asdcp/AS_DCP.h>
48 #include <asdcp/KM_fileio.h>
55 using std::shared_ptr;
56 using std::dynamic_pointer_cast;
57 using std::make_shared;
58 #if BOOST_VERSION >= 106100
59 using namespace boost::placeholders;
64 MonoPictureAsset::MonoPictureAsset (boost::filesystem::path file)
67 ASDCP::JP2K::MXFReader reader;
68 auto r = reader.OpenRead (
file.string().c_str());
69 if (ASDCP_FAILURE(r)) {
70 boost::throw_exception (
MXFFileError(
"could not open MXF file for reading",
file.string(), r));
73 ASDCP::JP2K::PictureDescriptor desc;
74 if (ASDCP_FAILURE (reader.FillPictureDescriptor(desc))) {
75 boost::throw_exception (
ReadError(
"could not read video MXF information"));
78 read_picture_descriptor (desc);
80 ASDCP::WriterInfo info;
81 if (ASDCP_FAILURE (reader.FillWriterInfo (info))) {
82 boost::throw_exception (
ReadError(
"could not read video MXF information"));
97 storing_note_handler (list<pair<NoteType, string>>& notes, NoteType t,
string s)
99 notes.push_back (make_pair (t, s));
104 MonoPictureAsset::equals (shared_ptr<const Asset> other,
EqualityOptions opt, NoteHandler note)
const
106 if (!dynamic_pointer_cast<const MonoPictureAsset>(other)) {
110 ASDCP::JP2K::MXFReader reader_A;
112 auto r = reader_A.OpenRead (
_file->string().c_str());
113 if (ASDCP_FAILURE(r)) {
114 boost::throw_exception (
MXFFileError(
"could not open MXF file for reading",
_file->string(), r));
117 ASDCP::JP2K::MXFReader reader_B;
118 DCP_ASSERT (other->file ());
119 r = reader_B.OpenRead (other->file()->string().c_str());
120 if (ASDCP_FAILURE (r)) {
121 boost::throw_exception (
MXFFileError (
"could not open MXF file for reading", other->file()->string(), r));
124 ASDCP::JP2K::PictureDescriptor desc_A;
125 if (ASDCP_FAILURE (reader_A.FillPictureDescriptor (desc_A))) {
126 boost::throw_exception (
ReadError (
"could not read video MXF information"));
128 ASDCP::JP2K::PictureDescriptor desc_B;
129 if (ASDCP_FAILURE (reader_B.FillPictureDescriptor (desc_B))) {
130 boost::throw_exception (
ReadError (
"could not read video MXF information"));
133 if (!descriptor_equals (desc_A, desc_B, note)) {
137 auto other_picture = dynamic_pointer_cast<const MonoPictureAsset> (other);
138 DCP_ASSERT (other_picture);
142 auto reader = start_read ();
143 auto other_reader = other_picture->start_read ();
146 #pragma omp parallel for
150 if (i >= other_picture->intrinsic_duration()) {
154 if (result || opt.keep_going) {
156 auto frame_A = reader->get_frame (i);
157 auto frame_B = other_reader->get_frame (i);
159 list<pair<NoteType, string>> notes;
161 if (!frame_buffer_equals (
162 i, opt, bind (&storing_note_handler, boost::ref(notes), _1, _2),
163 frame_A->data(), frame_A->size(),
164 frame_B->data(), frame_B->size()
173 note (NoteType::PROGRESS, String::compose(
"Compared video frame %1 of %2", i,
_intrinsic_duration));
174 for (
auto const& i: notes) {
175 note (i.first, i.second);
185 shared_ptr<PictureAssetWriter>
192 shared_ptr<MonoPictureAssetReader>
193 MonoPictureAsset::start_read ()
const
201 MonoPictureAsset::cpl_node_name ()
const
203 return "MainPicture";
boost::optional< boost::filesystem::path > file() const
boost::optional< boost::filesystem::path > _file
A fraction (i.e. a thing with an integer numerator and an integer denominator).
An exception related to an MXF file.
std::string read_writer_info(ASDCP::WriterInfo const &)
boost::optional< Key > key() const
A helper class for writing to MonoPictureAssets.
MonoPictureAsset(boost::filesystem::path file)
std::shared_ptr< PictureAssetWriter > start_write(boost::filesystem::path file, bool overwrite) override
An asset made up of JPEG2000 data.
int64_t _intrinsic_duration
Any error that occurs when reading data from a DCP.
Exceptions thrown by libdcp.
MonoPictureAssetReader typedef.
MonoPictureAssetWriter class.
Namespace for everything in libdcp.
A class to describe what "equality" means for a particular test.