Assorted C++11/formatting cleanups.
[dcpomatic.git] / src / lib / environment_info.cc
1 /*
2     Copyright (C) 2012-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 "log.h"
23 #include "compose.hpp"
24 #include "version.h"
25 #include "cross.h"
26 #include <dcp/version.h>
27 #include <libssh/libssh.h>
28 extern "C" {
29 #include <libavcodec/avcodec.h>
30 #include <libavformat/avformat.h>
31 #include <libavfilter/avfilter.h>
32 #include <libswscale/swscale.h>
33 #include <libavutil/pixfmt.h>
34 }
35 #include <boost/thread.hpp>
36
37 #include "i18n.h"
38
39
40 using std::list;
41 using std::pair;
42 using std::shared_ptr;
43 using std::string;
44
45
46 /** @param v Version as used by FFmpeg.
47  *  @return A string representation of v.
48  */
49 static
50 string
51 ffmpeg_version_to_string (int v)
52 {
53         char buffer[64];
54         snprintf (buffer, sizeof(buffer), "%d.%d.%d", ((v & 0xff0000) >> 16), ((v & 0xff00) >> 8), (v & 0xff));
55         return buffer;
56 }
57
58
59 /** Return a user-readable string summarising the versions of our dependencies */
60 static
61 string
62 dependency_version_summary ()
63 {
64         char buffer[512];
65         snprintf (
66                 buffer, sizeof(buffer), "libavcodec %s, libavfilter %s, libavformat %s, libavutil %s, libswscale %s, libssh %s, libdcp %s git %s",
67                 ffmpeg_version_to_string(avcodec_version()).c_str(),
68                 ffmpeg_version_to_string(avfilter_version()).c_str(),
69                 ffmpeg_version_to_string(avformat_version()).c_str(),
70                 ffmpeg_version_to_string(avutil_version()).c_str(),
71                 ffmpeg_version_to_string(swscale_version()).c_str(),
72                 ssh_version(0),
73                 dcp::version, dcp::git_commit
74                 );
75
76         return buffer;
77 }
78
79
80 list<string>
81 environment_info ()
82 {
83         list<string> info;
84
85         info.push_back (String::compose ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary()));
86
87         {
88                 char buffer[128];
89                 gethostname (buffer, sizeof (buffer));
90                 info.push_back (String::compose ("Host name %1", &buffer[0]));
91         }
92
93 #ifdef DCPOMATIC_DEBUG
94         info.push_back ("DCP-o-matic built in debug mode.");
95 #else
96         info.push_back ("DCP-o-matic built in optimised mode.");
97 #endif
98 #ifdef LIBDCP_DEBUG
99         info.push_back ("libdcp built in debug mode.");
100 #else
101         info.push_back ("libdcp built in optimised mode.");
102 #endif
103
104 #ifdef DCPOMATIC_WINDOWS
105         OSVERSIONINFO os_info;
106         os_info.dwOSVersionInfoSize = sizeof (os_info);
107         GetVersionEx (&os_info);
108         info.push_back (
109                 String::compose (
110                         "Windows version %1.%2.%3",
111                         (int) os_info.dwMajorVersion, (int) os_info.dwMinorVersion, (int) os_info.dwBuildNumber
112                         )
113                 );
114         if (os_info.dwMajorVersion == 5 && os_info.dwMinorVersion == 0) {
115                 info.push_back ("Windows 2000");
116         } else if (os_info.dwMajorVersion == 5 && os_info.dwMinorVersion == 1) {
117                 info.push_back ("Windows XP");
118         } else if (os_info.dwMajorVersion == 5 && os_info.dwMinorVersion == 2) {
119                 info.push_back ("Windows XP 64-bit or Windows Server 2003");
120         } else if (os_info.dwMajorVersion == 6 && os_info.dwMinorVersion == 0) {
121                 info.push_back ("Windows Vista or Windows Server 2008");
122         } else if (os_info.dwMajorVersion == 6 && os_info.dwMinorVersion == 1) {
123                 info.push_back ("Windows 7 or Windows Server 2008");
124         } else if (os_info.dwMajorVersion == 6 && (os_info.dwMinorVersion == 2 || os_info.dwMinorVersion == 3)) {
125                 info.push_back ("Windows 8 or Windows Server 2012");
126         } else if (os_info.dwMajorVersion == 10 && os_info.dwMinorVersion == 0) {
127                 info.push_back ("Windows 10 or Windows Server 2016");
128         }
129 #endif
130
131 #if __GNUC__
132 #if __x86_64__
133         info.push_back ("Built for x86 64-bit");
134 #elif __aarch64__
135         info.push_back ("Built for ARM 64-bit");
136 #else
137         info.push_back ("Built for x86 32-bit");
138 #endif
139 #endif
140
141         info.push_back (String::compose ("CPU: %1, %2 processors", cpu_info(), boost::thread::hardware_concurrency()));
142         for (auto const& i: mount_info()) {
143                 info.push_back (String::compose("Mount: %1 %2", i.first, i.second));
144         }
145
146         return info;
147 }