2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
34 #include "mono_picture_asset.h"
35 #include "mono_picture_asset_writer.h"
36 #include "mono_picture_asset_reader.h"
37 #include "exceptions.h"
38 #include "dcp_assert.h"
39 #include "mono_picture_frame.h"
40 #include "compose.hpp"
41 #include <asdcp/AS_DCP.h>
42 #include <asdcp/KM_fileio.h>
48 using std::shared_ptr;
49 using std::dynamic_pointer_cast;
50 #if BOOST_VERSION >= 106100
51 using namespace boost::placeholders;
55 MonoPictureAsset::MonoPictureAsset (boost::filesystem::path file)
58 ASDCP::JP2K::MXFReader reader;
59 Kumu::Result_t r = reader.OpenRead (file.string().c_str());
60 if (ASDCP_FAILURE (r)) {
61 boost::throw_exception (MXFFileError ("could not open MXF file for reading", file.string(), r));
64 ASDCP::JP2K::PictureDescriptor desc;
65 if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
66 boost::throw_exception (ReadError ("could not read video MXF information"));
69 read_picture_descriptor (desc);
71 ASDCP::WriterInfo info;
72 if (ASDCP_FAILURE (reader.FillWriterInfo (info))) {
73 boost::throw_exception (ReadError ("could not read video MXF information"));
76 _id = read_writer_info (info);
79 MonoPictureAsset::MonoPictureAsset (Fraction edit_rate, Standard standard)
80 : PictureAsset (edit_rate, standard)
86 storing_note_handler (list<pair<NoteType, string> >& notes, NoteType t, string s)
88 notes.push_back (make_pair (t, s));
92 MonoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
94 if (!dynamic_pointer_cast<const MonoPictureAsset> (other)) {
98 ASDCP::JP2K::MXFReader reader_A;
100 Kumu::Result_t r = reader_A.OpenRead (_file->string().c_str());
101 if (ASDCP_FAILURE (r)) {
102 boost::throw_exception (MXFFileError ("could not open MXF file for reading", _file->string(), r));
105 ASDCP::JP2K::MXFReader reader_B;
106 DCP_ASSERT (other->file ());
107 r = reader_B.OpenRead (other->file()->string().c_str());
108 if (ASDCP_FAILURE (r)) {
109 boost::throw_exception (MXFFileError ("could not open MXF file for reading", other->file()->string(), r));
112 ASDCP::JP2K::PictureDescriptor desc_A;
113 if (ASDCP_FAILURE (reader_A.FillPictureDescriptor (desc_A))) {
114 boost::throw_exception (ReadError ("could not read video MXF information"));
116 ASDCP::JP2K::PictureDescriptor desc_B;
117 if (ASDCP_FAILURE (reader_B.FillPictureDescriptor (desc_B))) {
118 boost::throw_exception (ReadError ("could not read video MXF information"));
121 if (!descriptor_equals (desc_A, desc_B, note)) {
125 shared_ptr<const MonoPictureAsset> other_picture = dynamic_pointer_cast<const MonoPictureAsset> (other);
126 DCP_ASSERT (other_picture);
130 shared_ptr<MonoPictureAssetReader> reader = start_read ();
131 shared_ptr<MonoPictureAssetReader> other_reader = other_picture->start_read ();
134 #pragma omp parallel for
137 for (int i = 0; i < _intrinsic_duration; ++i) {
138 if (i >= other_picture->intrinsic_duration()) {
142 if (result || opt.keep_going) {
144 shared_ptr<const MonoPictureFrame> frame_A = reader->get_frame (i);
145 shared_ptr<const MonoPictureFrame> frame_B = other_reader->get_frame (i);
147 list<pair<NoteType, string> > notes;
149 if (!frame_buffer_equals (
150 i, opt, bind (&storing_note_handler, boost::ref(notes), _1, _2),
151 frame_A->data(), frame_A->size(),
152 frame_B->data(), frame_B->size()
161 note (DCP_PROGRESS, String::compose ("Compared video frame %1 of %2", i, _intrinsic_duration));
162 for (list<pair<NoteType, string> >::const_iterator i = notes.begin(); i != notes.end(); ++i) {
163 note (i->first, i->second);
172 shared_ptr<PictureAssetWriter>
173 MonoPictureAsset::start_write (boost::filesystem::path file, bool overwrite)
175 /* XXX: can't we use shared_ptr here? */
176 return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, file, overwrite));
179 shared_ptr<MonoPictureAssetReader>
180 MonoPictureAsset::start_read () const
182 return shared_ptr<MonoPictureAssetReader> (new MonoPictureAssetReader (this, key(), standard()));
186 MonoPictureAsset::cpl_node_name () const
188 return "MainPicture";