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 DVDOMATIC_POSIX
29 #ifdef DVDOMATIC_WINDOWS
35 #include <sys/sysctl.h>
43 using boost::shared_ptr;
46 dvdomatic_sleep (int s)
48 #ifdef DVDOMATIC_POSIX
51 #ifdef DVDOMATIC_WINDOWS
56 /** @return A pair containing CPU model name and the number of processors */
60 pair<string, int> info;
63 #ifdef DVDOMATIC_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.first = l.substr (c + 2);
73 } else if (boost::algorithm::starts_with (l, "processor")) {
80 size_t N = sizeof (info.second);
81 sysctlbyname ("hw.ncpu", &info.second, &N, 0, 0);
84 if (sysctlbyname ("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) {
93 run_ffprobe (boost::filesystem::path content, boost::filesystem::path out, shared_ptr<Log> log)
95 #ifdef DVDOMATIC_WINDOWS
96 SECURITY_ATTRIBUTES security;
97 security.nLength = sizeof (security);
98 security.bInheritHandle = TRUE;
99 security.lpSecurityDescriptor = 0;
101 HANDLE child_stderr_read;
102 HANDLE child_stderr_write;
103 if (!CreatePipe (&child_stderr_read, &child_stderr_write, &security, 0)) {
104 log->log ("ffprobe call failed (could not CreatePipe)");
109 GetModuleFileName (GetModuleHandle (0), dir, sizeof (dir));
110 PathRemoveFileSpec (dir);
111 SetCurrentDirectory (dir);
113 STARTUPINFO startup_info;
114 ZeroMemory (&startup_info, sizeof (startup_info));
115 startup_info.cb = sizeof (startup_info);
116 startup_info.hStdError = child_stderr_write;
117 startup_info.dwFlags |= STARTF_USESTDHANDLES;
119 wchar_t command[512];
120 wcscpy (command, L"ffprobe.exe ");
123 MultiByteToWideChar (CP_UTF8, 0, content.string().c_str(), -1, file, sizeof(file));
124 wcscat (command, file);
126 PROCESS_INFORMATION process_info;
127 ZeroMemory (&process_info, sizeof (process_info));
128 if (!CreateProcess (0, command, 0, 0, TRUE, CREATE_NO_WINDOW, 0, 0, &startup_info, &process_info)) {
129 log->log ("ffprobe call failed (could not CreateProcess)");
133 FILE* o = fopen (out.string().c_str(), "w");
135 log->log ("ffprobe call failed (could not create output file)");
139 CloseHandle (child_stderr_write);
144 if (!ReadFile(child_stderr_read, buffer, sizeof(buffer), &read, 0) || read == 0) {
147 fwrite (buffer, read, 1, o);
152 WaitForSingleObject (process_info.hProcess, INFINITE);
153 CloseHandle (process_info.hProcess);
154 CloseHandle (process_info.hThread);
155 CloseHandle (child_stderr_read);
157 string ffprobe = "ffprobe \"" + content.string() + "\" 2> \"" + out.string() + "\"";
158 log->log (String::compose ("Probing with %1", ffprobe));
159 system (ffprobe.c_str ());
163 list<pair<string, string> >
166 list<pair<string, string> > m;
168 #ifdef DVDOMATIC_POSIX
169 FILE* f = setmntent ("/etc/mtab", "r");
175 struct mntent* mnt = getmntent (f);
180 m.push_back (make_pair (mnt->mnt_dir, mnt->mnt_type));