2 Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "mono_picture_asset.h"
21 #include "mono_picture_asset_writer.h"
23 #include "KM_fileio.h"
24 #include "exceptions.h"
25 #include "mono_picture_frame.h"
29 using boost::shared_ptr;
30 using boost::dynamic_pointer_cast;
31 using boost::lexical_cast;
34 MonoPictureAsset::MonoPictureAsset (boost::filesystem::path directory, boost::filesystem::path mxf_name)
35 : PictureAsset (directory, mxf_name)
41 MonoPictureAsset::read ()
43 ASDCP::JP2K::MXFReader reader;
44 Kumu::Result_t r = reader.OpenRead (path().string().c_str());
45 if (ASDCP_FAILURE (r)) {
46 boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
49 ASDCP::JP2K::PictureDescriptor desc;
50 if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
51 boost::throw_exception (DCPReadError ("could not read video MXF information"));
54 _size.width = desc.StoredWidth;
55 _size.height = desc.StoredHeight;
56 _edit_rate = desc.EditRate.Numerator;
57 assert (desc.EditRate.Denominator == 1);
58 _intrinsic_duration = desc.ContainerDuration;
61 boost::filesystem::path
62 MonoPictureAsset::path_from_list (int f, vector<boost::filesystem::path> const & files) const
67 shared_ptr<const MonoPictureFrame>
68 MonoPictureAsset::get_frame (int n) const
70 return shared_ptr<const MonoPictureFrame> (new MonoPictureFrame (path(), n, _decryption_context));
74 MonoPictureAsset::equals (shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
76 if (!MXFAsset::equals (other, opt, note)) {
80 ASDCP::JP2K::MXFReader reader_A;
81 Kumu::Result_t r = reader_A.OpenRead (path().string().c_str());
82 if (ASDCP_FAILURE (r)) {
83 boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
86 ASDCP::JP2K::MXFReader reader_B;
87 r = reader_B.OpenRead (other->path().string().c_str());
88 if (ASDCP_FAILURE (r)) {
89 boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
92 ASDCP::JP2K::PictureDescriptor desc_A;
93 if (ASDCP_FAILURE (reader_A.FillPictureDescriptor (desc_A))) {
94 boost::throw_exception (DCPReadError ("could not read video MXF information"));
96 ASDCP::JP2K::PictureDescriptor desc_B;
97 if (ASDCP_FAILURE (reader_B.FillPictureDescriptor (desc_B))) {
98 boost::throw_exception (DCPReadError ("could not read video MXF information"));
101 if (!descriptor_equals (desc_A, desc_B, note)) {
105 shared_ptr<const MonoPictureAsset> other_picture = dynamic_pointer_cast<const MonoPictureAsset> (other);
106 assert (other_picture);
108 for (int i = 0; i < _intrinsic_duration; ++i) {
109 if (i >= other_picture->intrinsic_duration()) {
113 note (PROGRESS, "Comparing video frame " + lexical_cast<string> (i) + " of " + lexical_cast<string> (_intrinsic_duration));
114 shared_ptr<const MonoPictureFrame> frame_A = get_frame (i);
115 shared_ptr<const MonoPictureFrame> frame_B = other_picture->get_frame (i);
117 if (!frame_buffer_equals (
119 frame_A->j2k_data(), frame_A->j2k_size(),
120 frame_B->j2k_data(), frame_B->j2k_size()
129 shared_ptr<PictureAssetWriter>
130 MonoPictureAsset::start_write (bool overwrite)
132 /* XXX: can't we use shared_ptr here? */
133 return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, overwrite));
137 MonoPictureAsset::cpl_node_name () const
139 return "MainPicture";
143 MonoPictureAsset::edit_rate_factor () const