It builds again.
[libdcp.git] / src / stereo_picture_mxf.cc
1 /*
2     Copyright (C) 2012-2013 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_mxf.h"
22 #include "stereo_picture_frame.h"
23 #include "exceptions.h"
24 #include "stereo_picture_mxf_writer.h"
25
26 using std::string;
27 using std::pair;
28 using std::make_pair;
29 using boost::shared_ptr;
30 using boost::dynamic_pointer_cast;
31 using namespace dcp;
32
33 StereoPictureMXF::StereoPictureMXF (boost::filesystem::path file)
34         : PictureMXF (file)
35 {
36         ASDCP::JP2K::MXFSReader reader;
37         Kumu::Result_t r = reader.OpenRead (file.string().c_str());
38         if (ASDCP_FAILURE (r)) {
39                 boost::throw_exception (MXFFileError ("could not open MXF file for reading", file.string(), r));
40         }
41         
42         ASDCP::JP2K::PictureDescriptor desc;
43         if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
44                 boost::throw_exception (DCPReadError ("could not read video MXF information"));
45         }
46
47         read_picture_descriptor (desc);
48 }
49
50 StereoPictureMXF::StereoPictureMXF (Fraction edit_rate)
51         : PictureMXF
52           (edit_rate)
53 {
54
55 }
56
57 shared_ptr<const StereoPictureFrame>
58 StereoPictureMXF::get_frame (int n) const
59 {
60         return shared_ptr<const StereoPictureFrame> (new StereoPictureFrame (file().string(), n));
61 }
62
63 shared_ptr<PictureMXFWriter>
64 StereoPictureMXF::start_write (boost::filesystem::path file, Standard standard, bool overwrite)
65 {
66         return shared_ptr<StereoPictureMXFWriter> (new StereoPictureMXFWriter (this, file, standard, overwrite));
67 }
68
69 int
70 StereoPictureMXF::edit_rate_factor () const
71 {
72         return 2;
73 }
74
75 bool
76 StereoPictureMXF::equals (shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
77 {
78         if (!MXF::equals (other, opt, note)) {
79                 return false;
80         }
81
82         ASDCP::JP2K::MXFSReader reader_A;
83         Kumu::Result_t r = reader_A.OpenRead (file().string().c_str());
84         if (ASDCP_FAILURE (r)) {
85                 boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r));
86         }
87         
88         ASDCP::JP2K::MXFSReader reader_B;
89         r = reader_B.OpenRead (other->file().string().c_str());
90         if (ASDCP_FAILURE (r)) {
91                 boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r));
92         }
93         
94         ASDCP::JP2K::PictureDescriptor desc_A;
95         if (ASDCP_FAILURE (reader_A.FillPictureDescriptor (desc_A))) {
96                 boost::throw_exception (DCPReadError ("could not read video MXF information"));
97         }
98         ASDCP::JP2K::PictureDescriptor desc_B;
99         if (ASDCP_FAILURE (reader_B.FillPictureDescriptor (desc_B))) {
100                 boost::throw_exception (DCPReadError ("could not read video MXF information"));
101         }
102         
103         if (!descriptor_equals (desc_A, desc_B, note)) {
104                 return false;
105         }
106         
107         shared_ptr<const StereoPictureMXF> other_picture = dynamic_pointer_cast<const StereoPictureMXF> (other);
108         assert (other_picture);
109
110         for (int i = 0; i < _intrinsic_duration; ++i) {
111                 shared_ptr<const StereoPictureFrame> frame_A = get_frame (i);
112                 shared_ptr<const StereoPictureFrame> frame_B = other_picture->get_frame (i);
113                 
114                 if (!frame_buffer_equals (
115                             i, opt, note,
116                             frame_A->left_j2k_data(), frame_A->left_j2k_size(),
117                             frame_B->left_j2k_data(), frame_B->left_j2k_size()
118                             )) {
119                         return false;
120                 }
121                 
122                 if (!frame_buffer_equals (
123                             i, opt, note,
124                             frame_A->right_j2k_data(), frame_A->right_j2k_size(),
125                             frame_B->right_j2k_data(), frame_B->right_j2k_size()
126                             )) {
127                         return false;
128                 }
129         }
130
131         return true;
132 }