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.
21 #include "stereo_picture_asset.h"
22 #include "stereo_picture_frame.h"
23 #include "exceptions.h"
24 #include "stereo_picture_asset_writer.h"
29 using boost::shared_ptr;
30 using boost::dynamic_pointer_cast;
34 StereoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
36 if (!MXFAsset::equals (other, opt, note)) {
40 ASDCP::JP2K::MXFSReader reader_A;
41 Kumu::Result_t r = reader_A.OpenRead (path().string().c_str());
42 if (ASDCP_FAILURE (r)) {
43 boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
46 ASDCP::JP2K::MXFSReader reader_B;
47 r = reader_B.OpenRead (other->path().string().c_str());
48 if (ASDCP_FAILURE (r)) {
49 boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
52 ASDCP::JP2K::PictureDescriptor desc_A;
53 if (ASDCP_FAILURE (reader_A.FillPictureDescriptor (desc_A))) {
54 boost::throw_exception (DCPReadError ("could not read video MXF information"));
56 ASDCP::JP2K::PictureDescriptor desc_B;
57 if (ASDCP_FAILURE (reader_B.FillPictureDescriptor (desc_B))) {
58 boost::throw_exception (DCPReadError ("could not read video MXF information"));
61 if (!descriptor_equals (desc_A, desc_B, note)) {
65 shared_ptr<const StereoPictureAsset> other_picture = dynamic_pointer_cast<const StereoPictureAsset> (other);
66 assert (other_picture);
68 for (int i = 0; i < _intrinsic_duration; ++i) {
69 shared_ptr<const StereoPictureFrame> frame_A = get_frame (i);
70 shared_ptr<const StereoPictureFrame> frame_B = other_picture->get_frame (i);
72 if (!frame_buffer_equals (
74 frame_A->left_j2k_data(), frame_A->left_j2k_size(),
75 frame_B->left_j2k_data(), frame_B->left_j2k_size()
80 if (!frame_buffer_equals (
82 frame_A->right_j2k_data(), frame_A->right_j2k_size(),
83 frame_B->right_j2k_data(), frame_B->right_j2k_size()
92 StereoPictureAsset::StereoPictureAsset (boost::filesystem::path directory, boost::filesystem::path mxf_name)
93 : PictureAsset (directory, mxf_name)
99 StereoPictureAsset::read ()
101 ASDCP::JP2K::MXFSReader reader;
102 Kumu::Result_t r = reader.OpenRead (path().string().c_str());
103 if (ASDCP_FAILURE (r)) {
104 boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r));
107 ASDCP::JP2K::PictureDescriptor desc;
108 if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
109 boost::throw_exception (DCPReadError ("could not read video MXF information"));
112 _size.width = desc.StoredWidth;
113 _size.height = desc.StoredHeight;
116 shared_ptr<const StereoPictureFrame>
117 StereoPictureAsset::get_frame (int n) const
119 return shared_ptr<const StereoPictureFrame> (new StereoPictureFrame (path().string(), n));
122 shared_ptr<PictureAssetWriter>
123 StereoPictureAsset::start_write (bool overwrite)
125 return shared_ptr<StereoPictureAssetWriter> (new StereoPictureAssetWriter (this, overwrite));
129 StereoPictureAsset::cpl_node_name () const
131 return "msp-cpl:MainStereoscopicPicture";
135 StereoPictureAsset::cpl_node_attribute () const
138 return make_pair ("xmlns:msp-cpl", "http://www.digicine.com/schemas/437-Y/2007/Main-Stereo-Picture-CPL");
140 return make_pair ("xmlns:msp-cpl", "http://www.smpte-ra.org/schemas/429-10/2008/Main-Stereo-Picture-CPL");
143 return make_pair ("", "");
147 StereoPictureAsset::edit_rate_factor () const