Cleanup: fix more comments/guards (and add check script).
[libdcp.git] / src / verify_report.cc
1 /*
2     Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp 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     libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 #include "compose.hpp"
36 #include "cpl.h"
37 #include "dcp.h"
38 #include "file.h"
39 #include "reel.h"
40 #include "reel_picture_asset.h"
41 #include "reel_sound_asset.h"
42 #include "reel_subtitle_asset.h"
43 #include "verify.h"
44 #include "verify_report.h"
45
46
47 using std::shared_ptr;
48 using std::string;
49 using std::vector;
50 using boost::optional;
51 using namespace dcp;
52
53
54 void write_line(File& file, string format)
55 {
56         file.puts(string(format + "\n").c_str());
57 }
58
59
60 template <typename... Args>
61 void write_line(File& file, string format, Args... args)
62 {
63         file.puts(String::compose(format + "\n", std::forward<Args>(args)...).c_str());
64 }
65
66
67 void
68 dcp::verify_report(dcp::VerificationResult const& result, Formatter& formatter)
69 {
70         auto document = formatter.document();
71         auto body = formatter.body();
72
73         formatter.heading("DCP verification report");
74
75         if (result.dcps.size() > 1) {
76                 formatter.subheading("DCPs");
77         } else {
78                 formatter.subheading("DCP");
79         }
80
81         auto reel_asset_details = [&formatter](shared_ptr<dcp::ReelAsset> asset) {
82                 formatter.list_item(String::compose("UUID: %1", asset->id()));
83                 formatter.list_item(String::compose("Intrinsic duration: %1", asset->intrinsic_duration()));
84                 formatter.list_item(String::compose("Entry point: %1", asset->entry_point().get_value_or(0)));
85                 formatter.list_item(String::compose("Duration: %1", asset->duration().get_value_or(0)));
86                 if (asset->annotation_text()) {
87                         formatter.list_item(String::compose("Annotation text: %1", *asset->annotation_text()));
88                 }
89         };
90
91         auto write_notes = [&formatter](dcp::VerificationResult const& result, optional<string> cpl_id) {
92                 for (auto note: result.notes) {
93                         if (note.cpl_id() == cpl_id) {
94                                 auto const note_as_string = dcp::note_to_string(note, formatter.process_string(), formatter.process_filename());
95                                 if (note.type() == dcp::VerificationNote::Type::OK) {
96                                         formatter.list_item(note_as_string, string("ok"));
97                                 } else if (note.type() == dcp::VerificationNote::Type::WARNING) {
98                                         formatter.list_item(note_as_string, string("warning"));
99                                 } else if (note.type() == dcp::VerificationNote::Type::ERROR) {
100                                         formatter.list_item(note_as_string, string("error"));
101                                 }
102                         }
103                 }
104         };
105
106         for (auto dcp: result.dcps) {
107                 auto ul = formatter.unordered_list();
108                 for (auto cpl: dcp->cpls()) {
109                         formatter.list_item(String::compose("CPL ID: %1", cpl->id()));
110                         int reel_index = 1;
111                         for (auto reel: cpl->reels()) {
112                                 formatter.list_item(String::compose("Reel: %1", reel_index++));
113                                 auto ul2 = formatter.unordered_list();
114                                 if (auto pic = reel->main_picture()) {
115                                         formatter.list_item("Main picture");
116                                         auto ul3 = formatter.unordered_list();
117                                         reel_asset_details(pic);
118                                         formatter.list_item(String::compose("Frame rate: %1", pic->frame_rate().numerator));
119                                         formatter.list_item(String::compose("Screen aspect ratio: %1x%2", pic->screen_aspect_ratio().numerator, pic->screen_aspect_ratio().denominator));
120                                 }
121                                 if (auto sound = reel->main_sound()) {
122                                         formatter.list_item("Main sound");
123                                         auto ul3 = formatter.unordered_list();
124                                         reel_asset_details(sound);
125                                 }
126                                 if (auto sub = reel->main_subtitle()) {
127                                         formatter.list_item("Main subtitle");
128                                         auto ul3 = formatter.unordered_list();
129                                         reel_asset_details(sub);
130                                         if (sub->language()) {
131                                                 formatter.list_item(String::compose("Language: %1", *sub->language()));
132                                         }
133                                 }
134                         }
135                         write_notes(result, cpl->id());
136                 }
137         }
138
139         if (std::count_if(result.notes.begin(), result.notes.end(), [](VerificationNote const& note) { return !note.cpl_id(); }) > 0) {
140                 formatter.subheading("Report");
141                 write_notes(result, {});
142         }
143 }
144