2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <boost/algorithm/string.hpp>
23 #include "compose.hpp"
25 #ifdef DCPOMATIC_LINUX
29 #ifdef DCPOMATIC_WINDOWS
35 #include <sys/sysctl.h>
44 using boost::shared_ptr;
47 dcpomatic_sleep (int s)
49 #ifdef DCPOMATIC_POSIX
52 #ifdef DCPOMATIC_WINDOWS
57 /** @return A string of CPU information (model name etc.) */
63 #ifdef DCPOMATIC_LINUX
64 ifstream f ("/proc/cpuinfo");
68 if (boost::algorithm::starts_with (l, "model name")) {
69 string::size_type const c = l.find (':');
70 if (c != string::npos) {
71 info = l.substr (c + 2);
79 size_t N = sizeof (buffer);
80 if (sysctlbyname ("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) {
85 #ifdef DCPOMATIC_WINDOWS
87 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key) != ERROR_SUCCESS) {
93 if (RegQueryValueEx (key, L"ProcessorNameString", 0, &type, 0, &data) != ERROR_SUCCESS) {
101 wstring value (data / sizeof (wchar_t), L'\0');
102 if (RegQueryValueEx (key, L"ProcessorNameString", 0, 0, reinterpret_cast<LPBYTE> (&value[0]), &data) != ERROR_SUCCESS) {
107 info = string (value.begin(), value.end());
117 run_ffprobe (boost::filesystem::path content, boost::filesystem::path out, shared_ptr<Log> log)
119 #ifdef DCPOMATIC_WINDOWS
120 SECURITY_ATTRIBUTES security;
121 security.nLength = sizeof (security);
122 security.bInheritHandle = TRUE;
123 security.lpSecurityDescriptor = 0;
125 HANDLE child_stderr_read;
126 HANDLE child_stderr_write;
127 if (!CreatePipe (&child_stderr_read, &child_stderr_write, &security, 0)) {
128 log->log ("ffprobe call failed (could not CreatePipe)");
133 GetModuleFileName (GetModuleHandle (0), dir, sizeof (dir));
134 PathRemoveFileSpec (dir);
135 SetCurrentDirectory (dir);
137 STARTUPINFO startup_info;
138 ZeroMemory (&startup_info, sizeof (startup_info));
139 startup_info.cb = sizeof (startup_info);
140 startup_info.hStdError = child_stderr_write;
141 startup_info.dwFlags |= STARTF_USESTDHANDLES;
143 wchar_t command[512];
144 wcscpy (command, L"ffprobe.exe \"");
147 MultiByteToWideChar (CP_UTF8, 0, content.string().c_str(), -1, file, sizeof(file));
148 wcscat (command, file);
150 wcscat (command, L"\"");
152 PROCESS_INFORMATION process_info;
153 ZeroMemory (&process_info, sizeof (process_info));
154 if (!CreateProcess (0, command, 0, 0, TRUE, CREATE_NO_WINDOW, 0, 0, &startup_info, &process_info)) {
155 log->log ("ffprobe call failed (could not CreateProcess)");
159 FILE* o = fopen (out.string().c_str(), "w");
161 log->log ("ffprobe call failed (could not create output file)");
165 CloseHandle (child_stderr_write);
170 if (!ReadFile(child_stderr_read, buffer, sizeof(buffer), &read, 0) || read == 0) {
173 fwrite (buffer, read, 1, o);
178 WaitForSingleObject (process_info.hProcess, INFINITE);
179 CloseHandle (process_info.hProcess);
180 CloseHandle (process_info.hThread);
181 CloseHandle (child_stderr_read);
183 string ffprobe = "ffprobe \"" + content.string() + "\" 2> \"" + out.string() + "\"";
184 log->log (String::compose ("Probing with %1", ffprobe));
185 system (ffprobe.c_str ());
189 list<pair<string, string> >
192 list<pair<string, string> > m;
194 #ifdef DCPOMATIC_LINUX
195 FILE* f = setmntent ("/etc/mtab", "r");
201 struct mntent* mnt = getmntent (f);
206 m.push_back (make_pair (mnt->mnt_dir, mnt->mnt_type));