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>
36 #include <mach-o/dyld.h>
45 using boost::shared_ptr;
48 dcpomatic_sleep (int s)
50 #ifdef DCPOMATIC_POSIX
53 #ifdef DCPOMATIC_WINDOWS
58 /** @return A string of CPU information (model name etc.) */
64 #ifdef DCPOMATIC_LINUX
65 ifstream f ("/proc/cpuinfo");
69 if (boost::algorithm::starts_with (l, "model name")) {
70 string::size_type const c = l.find (':');
71 if (c != string::npos) {
72 info = l.substr (c + 2);
80 size_t N = sizeof (buffer);
81 if (sysctlbyname ("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) {
86 #ifdef DCPOMATIC_WINDOWS
88 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key) != ERROR_SUCCESS) {
94 if (RegQueryValueEx (key, L"ProcessorNameString", 0, &type, 0, &data) != ERROR_SUCCESS) {
102 wstring value (data / sizeof (wchar_t), L'\0');
103 if (RegQueryValueEx (key, L"ProcessorNameString", 0, 0, reinterpret_cast<LPBYTE> (&value[0]), &data) != ERROR_SUCCESS) {
108 info = string (value.begin(), value.end());
118 run_ffprobe (boost::filesystem::path content, boost::filesystem::path out, shared_ptr<Log> log)
120 #ifdef DCPOMATIC_WINDOWS
121 SECURITY_ATTRIBUTES security;
122 security.nLength = sizeof (security);
123 security.bInheritHandle = TRUE;
124 security.lpSecurityDescriptor = 0;
126 HANDLE child_stderr_read;
127 HANDLE child_stderr_write;
128 if (!CreatePipe (&child_stderr_read, &child_stderr_write, &security, 0)) {
129 log->log ("ffprobe call failed (could not CreatePipe)");
134 GetModuleFileName (GetModuleHandle (0), dir, sizeof (dir));
135 PathRemoveFileSpec (dir);
136 SetCurrentDirectory (dir);
138 STARTUPINFO startup_info;
139 ZeroMemory (&startup_info, sizeof (startup_info));
140 startup_info.cb = sizeof (startup_info);
141 startup_info.hStdError = child_stderr_write;
142 startup_info.dwFlags |= STARTF_USESTDHANDLES;
144 wchar_t command[512];
145 wcscpy (command, L"ffprobe.exe \"");
148 MultiByteToWideChar (CP_UTF8, 0, content.string().c_str(), -1, file, sizeof(file));
149 wcscat (command, file);
151 wcscat (command, L"\"");
153 PROCESS_INFORMATION process_info;
154 ZeroMemory (&process_info, sizeof (process_info));
155 if (!CreateProcess (0, command, 0, 0, TRUE, CREATE_NO_WINDOW, 0, 0, &startup_info, &process_info)) {
156 log->log ("ffprobe call failed (could not CreateProcess)");
160 FILE* o = fopen (out.string().c_str(), "w");
162 log->log ("ffprobe call failed (could not create output file)");
166 CloseHandle (child_stderr_write);
171 if (!ReadFile(child_stderr_read, buffer, sizeof(buffer), &read, 0) || read == 0) {
174 fwrite (buffer, read, 1, o);
179 WaitForSingleObject (process_info.hProcess, INFINITE);
180 CloseHandle (process_info.hProcess);
181 CloseHandle (process_info.hThread);
182 CloseHandle (child_stderr_read);
185 #ifdef DCPOMATIC_LINUX
186 string ffprobe = "ffprobe \"" + content.string() + "\" 2> \"" + out.string() + "\"";
187 log->log (String::compose ("Probing with %1", ffprobe));
188 system (ffprobe.c_str ());
192 uint32_t size = 1024;
194 if (_NSGetExecutablePath (buffer, &size)) {
195 log->log ("_NSGetExecutablePath failed");
199 boost::filesystem::path path (buffer);
200 path.remove_filename ();
203 string ffprobe = path.string() + " \"" + content.string() + "\" 2> \"" + out.string() + "\"";
204 log->log (String::compose ("Probing with %1", ffprobe));
205 system (ffprobe.c_str ());
209 list<pair<string, string> >
212 list<pair<string, string> > m;
214 #ifdef DCPOMATIC_LINUX
215 FILE* f = setmntent ("/etc/mtab", "r");
221 struct mntent* mnt = getmntent (f);
226 m.push_back (make_pair (mnt->mnt_dir, mnt->mnt_type));