No-op: whitespace.
[libdcp.git] / src / stereo_picture_asset.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include "AS_DCP.h"
21 #include "stereo_picture_asset.h"
22 #include "stereo_picture_frame.h"
23 #include "exceptions.h"
24 #include "stereo_picture_asset_writer.h"
25 #include "dcp_assert.h"
26
27 using std::string;
28 using std::pair;
29 using std::make_pair;
30 using boost::shared_ptr;
31 using boost::dynamic_pointer_cast;
32 using namespace dcp;
33
34 StereoPictureAsset::StereoPictureAsset (boost::filesystem::path file)
35         : PictureAsset (file)
36 {
37         ASDCP::JP2K::MXFSReader reader;
38         Kumu::Result_t r = reader.OpenRead (file.string().c_str());
39         if (ASDCP_FAILURE (r)) {
40                 boost::throw_exception (MXFFileError ("could not open MXF file for reading", file.string(), r));
41         }
42
43         ASDCP::JP2K::PictureDescriptor desc;
44         if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
45                 boost::throw_exception (DCPReadError ("could not read video MXF information"));
46         }
47
48         read_picture_descriptor (desc);
49
50         ASDCP::WriterInfo info;
51         if (ASDCP_FAILURE (reader.FillWriterInfo (info))) {
52                 boost::throw_exception (DCPReadError ("could not read video MXF information"));
53         }
54
55         _id = read_writer_info (info);
56 }
57
58 StereoPictureAsset::StereoPictureAsset (Fraction edit_rate)
59         : PictureAsset
60           (edit_rate)
61 {
62
63 }
64
65 shared_ptr<const StereoPictureFrame>
66 StereoPictureAsset::get_frame (int n) const
67 {
68         return shared_ptr<const StereoPictureFrame> (new StereoPictureFrame (file().string(), n));
69 }
70
71 shared_ptr<PictureAssetWriter>
72 StereoPictureAsset::start_write (boost::filesystem::path file, Standard standard, bool overwrite)
73 {
74         return shared_ptr<StereoPictureAssetWriter> (new StereoPictureAssetWriter (this, file, standard, overwrite));
75 }
76
77 bool
78 StereoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
79 {
80         ASDCP::JP2K::MXFSReader reader_A;
81         Kumu::Result_t r = reader_A.OpenRead (file().string().c_str());
82         if (ASDCP_FAILURE (r)) {
83                 boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r));
84         }
85
86         ASDCP::JP2K::MXFSReader reader_B;
87         r = reader_B.OpenRead (other->file().string().c_str());
88         if (ASDCP_FAILURE (r)) {
89                 boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r));
90         }
91
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"));
95         }
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"));
99         }
100
101         if (!descriptor_equals (desc_A, desc_B, note)) {
102                 return false;
103         }
104
105         shared_ptr<const StereoPictureAsset> other_picture = dynamic_pointer_cast<const StereoPictureAsset> (other);
106         DCP_ASSERT (other_picture);
107
108         for (int i = 0; i < _intrinsic_duration; ++i) {
109                 shared_ptr<const StereoPictureFrame> frame_A;
110                 shared_ptr<const StereoPictureFrame> frame_B;
111                 try {
112                         frame_A = get_frame (i);
113                         frame_B = other_picture->get_frame (i);
114                 } catch (DCPReadError& e) {
115                         /* If there was a problem reading the frame data we'll just assume
116                            the two frames are not equal.
117                         */
118                         note (DCP_ERROR, e.what ());
119                         return false;
120                 }
121
122                 if (!frame_buffer_equals (
123                             i, opt, note,
124                             frame_A->left_j2k_data(), frame_A->left_j2k_size(),
125                             frame_B->left_j2k_data(), frame_B->left_j2k_size()
126                             )) {
127                         return false;
128                 }
129
130                 if (!frame_buffer_equals (
131                             i, opt, note,
132                             frame_A->right_j2k_data(), frame_A->right_j2k_size(),
133                             frame_B->right_j2k_data(), frame_B->right_j2k_size()
134                             )) {
135                         return false;
136                 }
137         }
138
139         return true;
140 }