Assorted C++11/formatting cleanups.
[dcpomatic.git] / src / lib / dcp.cc
1 /*
2     Copyright (C) 2014-2021 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
22 #include "compose.hpp"
23 #include "dcp.h"
24 #include "dcp_content.h"
25 #include "dcpomatic_log.h"
26 #include "log.h"
27 #include "util.h"
28 #include <dcp/dcp.h>
29 #include <dcp/decrypted_kdm.h>
30 #include <dcp/exceptions.h>
31
32 #include "i18n.h"
33
34
35 using std::list;
36 using std::string;
37 using std::shared_ptr;
38 using std::make_shared;
39 using std::dynamic_pointer_cast;
40 using std::vector;
41
42
43 /** Find all the CPLs in our directories, cross-add assets and return the CPLs */
44 list<shared_ptr<dcp::CPL>>
45 DCP::cpls () const
46 {
47         list<shared_ptr<dcp::DCP>> dcps;
48         list<shared_ptr<dcp::CPL>> cpls;
49
50         LOG_GENERAL ("Reading %1 DCP directories", _dcp_content->directories().size());
51         for (auto i: _dcp_content->directories()) {
52                 auto dcp = make_shared<dcp::DCP>(i);
53                 vector<dcp::VerificationNote> notes;
54                 dcp->read (&notes, true);
55                 if (!_tolerant) {
56                         /** We accept and ignore EMPTY_ASSET_PATH and EXTERNAL_ASSET but everything else is bad */
57                         for (auto j: notes) {
58                                 if (j.code() == dcp::VerificationNote::Code::EMPTY_ASSET_PATH || j.code() == dcp::VerificationNote::Code::EXTERNAL_ASSET) {
59                                         LOG_WARNING("Empty path in ASSETMAP of %1", i.string());
60                                 } else {
61                                         boost::throw_exception(dcp::ReadError(dcp::note_to_string(j)));
62                                 }
63                         }
64                 }
65                 dcps.push_back (dcp);
66                 LOG_GENERAL ("Reading DCP %1: %2 CPLs", i.string(), dcp->cpls().size());
67                 for (auto i: dcp->cpls()) {
68                         cpls.push_back (i);
69                 }
70         }
71
72         for (auto i: dcps) {
73                 for (auto j: dcps) {
74                         if (i != j) {
75                                 i->resolve_refs (j->assets (true));
76                         }
77                 }
78         }
79
80         if (_dcp_content->kdm ()) {
81                 auto k = decrypt_kdm_with_helpful_error (_dcp_content->kdm().get());
82                 for (auto i: dcps) {
83                         i->add (k);
84                 }
85         }
86
87         return cpls;
88 }