Fixes for new libdcp with multiple content versions.
[dcpomatic.git] / src / lib / copy_dcp_details_to_film.cc
1 /*
2     Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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.
10
11     DCP-o-matic 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.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "copy_dcp_details_to_film.h"
22 #include "dcp_content.h"
23 #include "film.h"
24 #include "types.h"
25 #include "video_content.h"
26 #include "audio_content.h"
27 #include "ratio.h"
28 #include "dcp_content_type.h"
29 #include <boost/shared_ptr.hpp>
30 #include <map>
31
32
33 using std::map;
34 using std::string;
35 using std::vector;
36 using boost::shared_ptr;
37
38
39 void
40 copy_dcp_details_to_film (shared_ptr<const DCPContent> dcp, shared_ptr<Film> film)
41 {
42         string name = dcp->name ();
43         name = name.substr (0, name.find("_"));
44         film->set_name (name);
45         film->set_use_isdcf_name (true);
46         if (dcp->content_kind()) {
47                 film->set_dcp_content_type (DCPContentType::from_libdcp_kind(dcp->content_kind().get()));
48         }
49         film->set_encrypted (dcp->encrypted());
50         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
51         film->set_interop (dcp->standard() == dcp::INTEROP);
52         film->set_three_d (dcp->three_d());
53
54         if (dcp->video) {
55                 film->set_container (Ratio::nearest_from_ratio(dcp->video->size().ratio()));
56                 film->set_resolution (dcp->resolution());
57                 DCPOMATIC_ASSERT (dcp->video_frame_rate());
58                 film->set_video_frame_rate (*dcp->video_frame_rate());
59         }
60
61         if (dcp->audio) {
62                 film->set_audio_channels (dcp->audio->stream()->channels());
63         }
64
65         map<dcp::Marker, dcpomatic::ContentTime> dcp_markers;
66         map<dcp::Marker, dcpomatic::DCPTime> film_markers;
67         film->clear_markers ();
68         for (map<dcp::Marker, dcpomatic::ContentTime>::const_iterator i = dcp_markers.begin(); i != dcp_markers.end(); ++i) {
69                 film->set_marker (i->first, dcpomatic::DCPTime(i->second.get()));
70         }
71
72         film->set_ratings (dcp->ratings());
73         film->set_content_versions (dcp->content_versions());
74 }
75