Add another believed-correct subtitle timing fix.
[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         /** We accept and ignore some warnings / errors but everything else is bad */
51         vector<dcp::VerificationNote::Code> ignore = {
52                 dcp::VerificationNote::Code::EMPTY_ASSET_PATH,
53                 dcp::VerificationNote::Code::EXTERNAL_ASSET,
54                 dcp::VerificationNote::Code::THREED_ASSET_MARKED_AS_TWOD,
55         };
56
57         LOG_GENERAL ("Reading %1 DCP directories", _dcp_content->directories().size());
58         for (auto i: _dcp_content->directories()) {
59                 auto dcp = make_shared<dcp::DCP>(i);
60                 vector<dcp::VerificationNote> notes;
61                 dcp->read (&notes, true);
62                 if (!_tolerant) {
63                         for (auto j: notes) {
64                                 if (std::find(ignore.begin(), ignore.end(), j.code()) != ignore.end()) {
65                                         LOG_WARNING("Ignoring: %1", dcp::note_to_string(j));
66                                 } else {
67                                         boost::throw_exception(dcp::ReadError(dcp::note_to_string(j)));
68                                 }
69                         }
70                 }
71                 dcps.push_back (dcp);
72                 LOG_GENERAL ("Reading DCP %1: %2 CPLs", i.string(), dcp->cpls().size());
73                 for (auto i: dcp->cpls()) {
74                         cpls.push_back (i);
75                 }
76         }
77
78         for (auto i: dcps) {
79                 for (auto j: dcps) {
80                         if (i != j) {
81                                 i->resolve_refs(j->assets());
82                         }
83                 }
84         }
85
86         if (_dcp_content->kdm ()) {
87                 auto k = decrypt_kdm_with_helpful_error (_dcp_content->kdm().get());
88                 for (auto i: dcps) {
89                         i->add (k);
90                 }
91         }
92
93         return cpls;
94 }